Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QScrollArea Does Not Respond To Mouse Wheel
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QScrollArea Does Not Respond To Mouse Wheel

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elveatles
    wrote on 2 Jul 2013, 22:50 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 3 Jul 2013, 02:04 last edited by
      #2

      Hi, can you show us where the wheelEvent related code you have put in?

      1 Reply Last reply
      0
      • E Offline
        E Offline
        elveatles
        wrote on 3 Jul 2013, 02:14 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elveatles
          wrote on 3 Jul 2013, 23:42 last edited by
          #4

          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.

          1 Reply Last reply
          0

          1/4

          2 Jul 2013, 22:50

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved