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. QTableView - Limit number of selected items?
Forum Updated to NodeBB v4.3 + New Features

QTableView - Limit number of selected items?

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

    The question is in the title.
    There is no function QTableView::set_Max_Number_SelectedItems( int ).

    When the number of selected items is 2, I want to disable selection of item.

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DBoosalis
      wrote on last edited by
      #2

      A couple of ways come to mind

      1. Set the TableView to single selection mode, and create your Delegate. Inside the Delegate's paint event you can override how it gets painted by checking some data you have set for that index. For each selection you have your selectionChangedSlot called where you can keep track of which ones get selected and deselected setting the data for that index.

      2. QTableView has a protected methods "emitSelectionChanged()". For which I imagine gets called before the selectionChanged signal does, so here you can make sure no more then two items are to be in the selection model (QItemSelectionModel) .

      Sorry for all the hand waiving here, if I can explain it any more let me know and I will try

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

        Hi,

        What about implementing your own QItemSelectionModel ? You can reimplement the select slots and do nothing if the selection size is two.

        Hope it helps

        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
        • J Offline
          J Offline
          jp_doyon1
          wrote on last edited by
          #4

          @DBoosalis, thanks for your answer.
          The solution I choosed is described here.

          http://stackoverflow.com/questions/27272543/qtableview-limit-number-of-selected-items

          Cheers all.

          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