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] How to find out whether child widget of QScroll Area is visible?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to find out whether child widget of QScroll Area is visible?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k 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.
  • J Offline
    J Offline
    jesuisbenjamin
    wrote on last edited by
    #1

    Hello,

    I am displaying multiple QLabels on a QFrame, placed into a QScrollArea. I am able to tell QScrollArea to make any of the QLabels visible with QScrollArea.ensureVisible(QLabel), but I cannot seem to find a method to find out whether the child widget is currently visible or not. I would expect something like QScrollArea.isWidgetVisible(QWidget). I tried using the child's own method, i.e. QLabel.isVisible() but no matter whether the QLabel is visible or not in the QScrollArea, it always returns True. What's the solution?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jesuisbenjamin
      wrote on last edited by
      #2

      I got an answer from "StackOverflow":http://stackoverflow.com/questions/10631067/how-to-find-out-whether-child-widget-of-qscrollarea-is-visible:

      I proposed the following code:
      @
      #!/usr/bin/env python

      import sys
      from PyQt4 import QtGui, QtCore

      application = QtGui.QApplication(sys.argv)

      class Area(QtGui.QScrollArea):

      def __init__(self, child):
              super(Area, self).__init__()
          self.child = child
          self.setWidget(self.child)
          self.setFixedSize(100, 100)
      

      class MainWidget(QtGui.QFrame):

      def __init__(self, parent=None):
              QtGui.QFrame.__init__(self, parent)
          self.layout = QtGui.QVBoxLayout()
          n = 1
          while n != 10:
              label = QtGui.QLabel('<h1>'+str(n)+'</h1>')
              self.layout.addWidget(label)
              n += 1
          self.setLayout(self.layout)
      
      def wheelEvent(self, event):
          print "Wheel Event:"
          for child in self.children()[1:]:
              print child.isVisible()
          event.ignore()
      

      mainwidget = MainWidget()
      area = Area(mainwidget)
      area.show()
      application.exec_()
      @

      And it was suggested I change the wheelEvent() method as such:

      @
      def wheelEvent(self, event):
      print "Wheel Event:"
      for child in self.children()[1:]:
      print child.text(), 'is visible?', not child.visibleRegion().isEmpty()
      event.ignore()
      @

      And that does the job! :)

      1 Reply Last reply
      0

      • Login

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