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. Qt 6.7.0: QTableWidget.itemAt() always returns first QTableWidgetItem passed to setItem
Forum Update on Monday, May 27th 2025

Qt 6.7.0: QTableWidget.itemAt() always returns first QTableWidgetItem passed to setItem

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 289 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    The following test case fails qith PyQt-6.6.1 and Qt-6.7.0:

    def test_QTableWidget_ids(qtbot):
        item_0 = QTableWidgetItem()
        item_1 = QTableWidgetItem()
        item_2 = QTableWidgetItem()
        w = QTableWidget(3, 3)
        w.setItem(0, 0, item_0)
        w.setItem(1, 0, item_1)
        w.setItem(2, 0, item_2)
        assert id(w.itemAt(0, 0)) != id(w.itemAt(1, 0))
        assert id(w.itemAt(1, 0)) != id(w.itemAt(2, 0))
    

    QTableWidget.itemAt returns the first QTableWidgetItem passed to QTableWidget.setItem regardless of coordinates passed to either method and regardless of number of calls to setItem with different QTableWidgetItem's. What gives?? is this some new functionality in Qt 6 that requires a different setting? Or a bug in PyQt6 maybe?

    https://alaskafamilysystems.com/

    1 Reply Last reply
    0
    • P Offline
      P Offline
      patrickkidd
      wrote on last edited by
      #2

      I figured it out. I was calling itemAt() instead of item(). Been correctly making that call for 20 years. Friday brain wins again :)

      https://alaskafamilysystems.com/

      1 Reply Last reply
      0
      • SGaistS SGaist has marked this topic as solved on
      • FeRDNYCF Offline
        FeRDNYCF Offline
        FeRDNYC
        wrote on last edited by
        #3

        Don't feel bad. That one's been tripping people up for at least 14 years now.

        1 Reply Last reply
        1
        • FeRDNYCF Offline
          FeRDNYCF Offline
          FeRDNYC
          wrote on last edited by
          #4

          (Hint: For those playing along at home, itemAt(x, y) returns the item under those pixel coordinates in the widget. item(row, col) returns the item in the specified table cell.)

          1 Reply Last reply
          1

          • Login

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