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. Qt::ItemIsSelectable and QTreeView
Forum Updated to NodeBB v4.3 + New Features

Qt::ItemIsSelectable and QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.2k 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.
  • mspauldingM Offline
    mspauldingM Offline
    mspaulding
    wrote on last edited by mspaulding
    #1

    After playing around with the following function:

    virtual Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex& index) const;
    

    as expected, not returning Qt::ItemIsSelectable prevents the item from being selected/unselected, but it also gets removed from the selectionModel().selectedIndicies() list even if it was last known to be selected. There is never a notification of a selection change for that item, so it still appears as selected.

    I would think that not returning Qt::ItemIsSelectable would only prevent an item from changing it's selection state, not completely removing all selection related functionality.

    The use case here is that I would like to have items in a tree view that are in a "locked" state where selection cannot be changed, but are still properly reported as selected by the model.

    I am currently working around this by allowing a selection change but immediately changing it right back, which seems to function without visible artifacts but does not seem ideal.

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

      Could you post your code?

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by jeremy_k
        #3

        QItemSelectionModel::select() is virtual. Subclassing and overriding select to ignore the items that can't be changed might work.

        edit: 4.5 years later... Reviving long dormant threads seems to be popular.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        1
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Sounds very similar to QTBUG-88723.

          The code that excludes items that are not selectable and enabled is in indexesFromRange() and it's been there since the trolltech days. You can't use the isSelected() workaround in the bug report either as it only works around the Qt::ItemIsEnabled check so i reckon allowing the change and change it back is the way to go here. Connect a slot to QItemSelectionModel::selectionChanged that reverts the changes you don't want to happen

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          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