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. Allow selection of only single item in QItemSelectionModel
Forum Updated to NodeBB v4.3 + New Features

Allow selection of only single item in QItemSelectionModel

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.4k 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I have a TableView which uses an ItemSelectionModel for selection of rows. While it is working (I can select rows), I want to limit my selection to a single row only. In other words, if a row is already selected, deselect the old one and select only the new one. Using shift/ctl should not allow more than a single row to be selected.

    Although I am using ItemSelectionModel in QML, this seems to be just a wrapper for QItemSelectionModel (and this forum seems to get more answers than QML forum). Can someone advise on the combination of selection flags I need to use? (I've tried a bunch of combinations and can't find one that does what I want).

    I have read the selection flag documentation but I'm no further ahead (in fact its a bit confusing).

    If I call select with options "Current" | "Toggle" then I will limit selection to a single row; however, it does not allow me to DESELECT that row by clicking on it again. (i.e. not toggling)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by mchinand
      #2

      Edit: Seems these options are available for the Widgets QTableView but there doesn't seem to be corresponding options in QML.

      I think you want to set the SelectionBehavior to QAbstractItemView::SelectRows
      and the SelectionMode to QAbstractItemView::SingleSelection.

      1 Reply Last reply
      0
      • ocgltdO Offline
        ocgltdO Offline
        ocgltd
        wrote on last edited by
        #3

        You're right - those properties are not exposed to the QML class. I guess I'll have to code a deselect, then select on click

        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