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. Switch selection mode
Qt 6.11 is out! See what's new in the release blog

Switch selection mode

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.5k Views 2 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.
  • N Offline
    N Offline
    nnzz
    wrote on last edited by
    #1

    Hi, I have a QTableView, I'm using SelectRow, and I want single-row selection by default and multi-selection when the <ctrl> key is pressed.
    What is the best practice for this?
    Currently I manage that myself: I listen to the QTableView::clicked signal and check the keyboardModifiers, it seems awkword

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

      Hi,

      QTableView::setSelectionMode
      QTableView::setSelectionBehavior

      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
      2
      • N Offline
        N Offline
        nnzz
        wrote on last edited by
        #3

        When should I switch the mode? What signal should I connect to?
        Currently I turn the selection of other rows myself, is that logical???

        1 Reply Last reply
        0
        • N nnzz

          Hi, I have a QTableView, I'm using SelectRow, and I want single-row selection by default and multi-selection when the <ctrl> key is pressed.
          What is the best practice for this?
          Currently I manage that myself: I listen to the QTableView::clicked signal and check the keyboardModifiers, it seems awkword

          Taz742T Offline
          Taz742T Offline
          Taz742
          wrote on last edited by Taz742
          #4

          @nnzz said in Switch selection mode:

          Currently I manage that myself: I listen to the QTableView::clicked signal and check the keyboardModifiers, it seems awkword

          Why ? :/ It already has Qt.
          Why not use MultiSelection ?

          Do what you want.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nnzz
            wrote on last edited by
            #5

            I only need multi selection when the <ctrl> key is pressed, otherwise I need single row.
            I am currently using multi selection and checking the <ctrl> key state, in order to release previous selections, that seems weird

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

              That's what ExtendedSelection does. Take a look at the SelectionBehavior enum description.

              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

              • Login

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