dev/qt/ PyQtWidgets1
ScrollArea
Inherits from QAbstractScrollArea.
Typo Alert on the Qt website docs for QScrollArea we see:
imageLabel = QLabel()
image = QImage("happyguy.png")
imageLabel.setPixmap(QPixmap.fromImage(image))
scrollArea = QScrollArea
scrollArea.setBackgroundRole(QPalette.Dark)
scrollArea.setWidget(imageLabel)
and the QScrollArea
should be QScrollArea()
, i.e.
imageLabel = QLabel()
image = QImage("happyguy.png")
imageLabel.setPixmap(QPixmap.fromImage(image))
scrollArea = QScrollArea() # <----------------------- parens() here
scrollArea.setBackgroundRole(QPalette.Dark)
scrollArea.setWidget(imageLabel)
Example App
#!/usr/bin/env python3
import sys
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
app = QApplication(sys.argv)
win = QMainWindow()
imageLabel = QLabel()
image = QImage("a.png")
imageLabel.setPixmap(QPixmap.fromImage(image))
scrollArea = QScrollArea()
scrollArea.setBackgroundRole(QPalette.Dark)
scrollArea.setWidget(imageLabel)
win.setCentralWidget(scrollArea)
win.show()
exit(app.exec())