[SOLVED] QScrollArea Does Not Respond To Mouse Wheel
-
I'm using PySide, but the problem is probably the same in PyQt or C++ Qt.
I've created a QScrollArea with a bunch of QLabels and QTreeWidgets. If I use the mouse wheel while hovering over the contents, it doesn't do anything. The mouse wheel works if you hover over the scroll bar though, which isn't much help.Here's part of the code to show what I'm doing.
@
self.scrollAreaWidget = QtGui.QWidget()self.scrollArea = QtGui.QScrollArea(self.centralWidget)
self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark)
self.scrollArea.setWidget(self.scrollAreaWidget)self.scrollAreaRootLayout = QtGui.QVBoxLayout()
self.scrollAreaRootLayout.setContentsMargins(0, 0, 0, 0)
self.scrollArea.setLayout(self.scrollAreaRootLayout)
self.scrollAreaRootLayout.addWidget(self.scrollAreaWidget)
self.scrollAreaLayout = QtGui.QVBoxLayout()
self.scrollAreaLayout.setContentsMargins(0, 7, 0, 0)
self.scrollAreaWidget.setLayout(self.scrollAreaLayout)
@Then I go through a for loop of adding labels and trees.
This is the function that gets called multiple times in the for loop
@
def addTree(self, labelText, files):
label = QtGui.QLabel()
label.setText(labelText)
label.setFont(self.separatorFont)
label.setIndent(14)self.scrollAreaLayout.addWidget(label)
treeWidget = TreeWidgetExpanding()
treeWidget.header().close()
treeWidget.itemClicked.connect(self.onItemClicked)pathHierarchy = external_files.PathHierarchy()
for item in files:
pathHierarchy.add(item)self.addItems(treeWidget, pathHierarchy.rootDir)
self.scrollAreaLayout.addWidget(treeWidget)
@Thank you to anyone taking the time to reply.
-
Hi, can you show us where the wheelEvent related code you have put in?
-
Sorry, I'm kind of new to Qt. I thought that having a QScrollView was enough for wheel scrolling to just work as expected, so I didn't make any custom wheelEvent code. I was referencing the example imageviewer for a working scroll area, and it didn't seem like there was any wheelEvent code there.
-
I took out the self.scrollAreaRootLayout, used self.scrollArea.setWidgetResizable(True), and it works. It also fixed a few other problems I was going to ask about.