Dup Goto 📝

PyQtWidgets1

PT2/aw/dev/qt 07-31 13:46:42
To Pop
47 lines, 103 words, 1345 chars Monday 2023-07-31 13:46:42

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())