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. Hiding a table advances the selected item
Forum Updated to NodeBB v4.3 + New Features

Hiding a table advances the selected item

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 943 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.
  • F Offline
    F Offline
    fname
    wrote on last edited by
    #1

    I've tried this with both a QTableView and a QTableWidget. I want to make my table invisible and then later show it again. If I've selected a table item, and at some point I call hide() on the table, the table deselects the currently selected item and selects the next item. This will be shown visually when I call show() on the table.

    I can manually override this behavior by manually re-selecting the previous item after calling hide(), but this becomes an unfixable mess when multiple items had been selected. No amount of fiddling with clearSelection() and selectRow() seems to be able to restore the original multi-item selection in that situation.

    Long story short, whenever I call hide() on my table, the current selection advances. Is it possible to avoid this strange behavior?

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

      Hi,

      Sounds like a pretty strange bug ! Which version of Qt are you using ? Can you reproduce this with a minimal compilable example ?

      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
      • F Offline
        F Offline
        fname
        wrote on last edited by
        #3

        I'm using PyQt4 on Windows, version 4.8.5. (Update: I also tried the latest version of PyQt, and the latest version of PySide -- same problem).

        This minimalistic code snippet demonstrates the problem. It waits 5 seconds, giving the user time to select a table item, then hides and immediately afterwards shows the table. (It doesn't matter if there's a delay between hiding and showing.)

        [code]
        from PyQt4.QtGui import *
        from PyQt4.QtCore import *

        app = QApplication([])
        window = QMainWindow()
        window.resize(300, 200)

        table = QTableWidget(window)
        table.resize(300, 200)

        table.setRowCount(4)
        table.setColumnCount(2)

        Fill the 4x2 table with items saying "data"

        for r in range(4):
        for c in range(2):
        item = QTableWidgetItem("data")
        table.setItem(r, c, item)

        This function will be called 5 seconds after the program starts

        def DelayedAction():
        table.hide()
        table.show()

        QTimer.singleShot(5000, DelayedAction)

        window.show()
        app.exec_()
        [/code]

        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