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. Prevent deselection of Table view row
Qt 6.11 is out! See what's new in the release blog

Prevent deselection of Table view row

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 587 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.
  • E Offline
    E Offline
    EaccB
    wrote on last edited by
    #1

    If you have a non-empty table view, is there a way to prevent the user from deselecting a row using command+click, etc? I.e, a row must always be selected if the the row count is > 0.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Not without overwriting QItemSelectionModel::select()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • E Offline
        E Offline
        EaccB
        wrote on last edited by
        #3

        Thanks. How would I do that though?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @EaccB said in Prevent deselection of Table view row:

          How would I do that though?

          I don't understand what you mean - I already told you what you've to do.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          E 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @EaccB said in Prevent deselection of Table view row:

            How would I do that though?

            I don't understand what you mean - I already told you what you've to do.

            E Offline
            E Offline
            EaccB
            wrote on last edited by
            #5

            @Christian-Ehrlicher

            I'm not sure how I would implement this functionality in select().

            mrjjM 1 Reply Last reply
            0
            • E EaccB

              @Christian-Ehrlicher

              I'm not sure how I would implement this functionality in select().

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @EaccB
              Hi
              I think you would inherit QItemSelectionModel and then override select.
              Then use this new object in the TreeView with
              https://doc.qt.io/qt-5/qtableview.html#setSelectionModel

              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