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. QTableView Multi-Selection
Forum Updated to NodeBB v4.3 + New Features

QTableView Multi-Selection

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 1.3k 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.
  • R Offline
    R Offline
    richard_gr20
    wrote on last edited by
    #1

    Hello,
    I'm just getting started on handling multi-selection in a Pyside6 QTableView. I'm still learning the concepts and how it can work.
    Can someone give high-level advice on what needs to be done? I haven't found an example in this forum yet nor on the internet.

    I am working with PySide6, I should be able to follow C++ advice.
    I see that the QTableView object derives from QAbstractItemView which has a state that can be queried.
    I think that tracking the state for cell clicked and cell entered will be needed.
    The state is equal to NoState for the first cell entered.
    The state is equal to NoState for the first cell clicked.
    I observe that the entered slot is called first then the clicked slot. That seems obvious, is the order guaranteed?
    If you hold the shift key and drag the mouse then the cells you drag into will have the DragSelectingState.

    1. So for multi-selection I may need to track/record that first cell in the clicked slot handler and then when entered is called with state = DragSelectingState,
      see if the very first cell clicked is one cell before the first dragged into cell.
    2. Put another way, in the entered slot handler if DragSelectingState is True then an adjacent cell must have been entered with a mouse click.
      And that adjacent cell needed to be tracked/recorded so that the cells dragged into can determine the first cell.

    I have set these properties on the table_view (QTableView) object:
    table_view.setSelectionMode(QAbstractItemView.ExtendedSelection)
    table_view.SelectionBehavior(QAbstractItemView.SelectRows)
    table_view.setMouseTracking(True)

    I've made these signal-slot connections:
    table_view.clicked.connect(self.func_table_view_cell_clicked)
    table_view.entered.connect(self._cell_entered)

    Am I grasping the key concepts correctly?
    Does anyone have any sample code that I can refer to?

    Thanks for any help that you can provide,
    Richard

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

      Hi and welcome to devnet,

      Wouldn't QItemSelectionModel cover your needs ?

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

      R 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Wouldn't QItemSelectionModel cover your needs ?

        R Offline
        R Offline
        richard_gr20
        wrote on last edited by
        #3

        @SGaist Thank you for that tip. I am researching QItemSelectionModel now.

        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