Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Find what rows are visible in a scrolling table

Find what rows are visible in a scrolling table

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 4 Posters 1.5k Views
  • 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.
  • A Offline
    A Offline
    ACollins
    wrote on last edited by
    #1

    I would appreciate if somebody can point me in the right direction. I have a table with 1 column and 60 rows of which 24 rows are visible at any one time. This table has 24 checkboxes on the side, one for each visible row. When a person clicks on the checkbox how can I find out which row was selected? If I can find out the top most row that is visible I can find out everything else. Is there any function that will tell me that say, 7th row is the top most visible row at this time? Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      No there's no such method. However you can use visualRect to achieve that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ACollins
        wrote on last edited by
        #3

        SGaist: Thanks but I just started working with qt and visualRect is well beyond my grasp at this juncture.

        Denni: I took your advice and added the checkboxes into the table using the code from the answer section of this post:
        https://stackoverflow.com/questions/48057638/how-should-i-connect-checkbox-clicked-signals-in-table-widgets-in-pyqt5

        Now how do I center this checkbox in the table cell? Thanks.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ACollins
          wrote on last edited by
          #4

          My code for inserting the checkbox in the table looks like this. The checkbox comes out as left-justified and I would like to center it. Thanks.

              for i in range(self.tableWidget.rowCount()):
                  ch = QtWidgets.QCheckBox(parent=self.tableWidget)
                  ch.clicked.connect(lambda checked, row=0, col=i: self.onStateChanged(checked, row, col))
                  self.tableWidget.setCellWidget(i, 0, ch)
          
          JonBJ 1 Reply Last reply
          0
          • A ACollins

            My code for inserting the checkbox in the table looks like this. The checkbox comes out as left-justified and I would like to center it. Thanks.

                for i in range(self.tableWidget.rowCount()):
                    ch = QtWidgets.QCheckBox(parent=self.tableWidget)
                    ch.clicked.connect(lambda checked, row=0, col=i: self.onStateChanged(checked, row, col))
                    self.tableWidget.setCellWidget(i, 0, ch)
            
            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @ACollins said in Find what rows are visible in a scrolling table:

            ch.clicked.connect(lambda checked, row=0, col=i: self.onStateChanged(checked, row, col))

            Before you overlook it, I presume you intend:

            ch.clicked.connect(lambda checked, row=i, col=0: self.onStateChanged(checked, row, col))
            

            (row/col values swapped).

            This isn't the best way to do things [ I'm looking at you, @VRonin ;-) ], but from where you are now presumably you can always:

                    w =  QtWidgets.QWidget(parent=self.tableWidget)
                    w.setLayout(QtWidgets.QHBoxLayout())
                    ch = QtWidgets.QCheckBox()
                    w.layout().addWidget(ch)
                    ch.clicked.connect(lambda checked, row=i, col=0: self.onStateChanged(checked, row, col))
                    self.tableWidget.setCellWidget(i, 0, w)
            

            i.e. just put the checkbox in a horizontal layout.

            I'm not sure why in the code you copied from the author goes for a setCellWidget(QCheckBox) at all. Wouldn't a blank QTableWidgetItem with setFlags(... or Qt.ItemIsUserCheckable) suffice?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ACollins
              wrote on last edited by
              #6

              Thank you very much JonB & Denni. All good and working perfectly!

              Denni: I wasn't sure what MUC is. I have been away from programming for 15+ years so this lingo is all new. I think I will read the FAQ.

              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