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. Gray out an item in TreeView without making it not selectable / right-clickable
Forum Updated to NodeBB v4.3 + New Features

Gray out an item in TreeView without making it not selectable / right-clickable

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.8k 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by
    #1

    Hi,

    i have a QTreeView, that display a custom TreeModel.
    Now i want to activate/deactivate item (by right-clicking them)

    Deactivating works by setting the falg to not be Qt::ItemIsEnabled.
    However then i cannot activate it again since when the flag Qt::ItemIsEnabled is not set the rightclick does not work any more and the item is not selectable.

    Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?

    JonBJ raven-worxR 2 Replies Last reply
    0
    • gde23G gde23

      Hi,

      i have a QTreeView, that display a custom TreeModel.
      Now i want to activate/deactivate item (by right-clicking them)

      Deactivating works by setting the falg to not be Qt::ItemIsEnabled.
      However then i cannot activate it again since when the flag Qt::ItemIsEnabled is not set the rightclick does not work any more and the item is not selectable.

      Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @gde23
      You could use a stylesheet or QStyledItemDelegate to alter its display to some sort of "dimmed". You would need to store the desired state somewhere, such as in the item's data.

      1 Reply Last reply
      1
      • gde23G gde23

        Hi,

        i have a QTreeView, that display a custom TreeModel.
        Now i want to activate/deactivate item (by right-clicking them)

        Deactivating works by setting the falg to not be Qt::ItemIsEnabled.
        However then i cannot activate it again since when the flag Qt::ItemIsEnabled is not set the rightclick does not work any more and the item is not selectable.

        Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:

        Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?

        return a desired color for Qt::ForegroundRole for the corresponding index in your data() implementation.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        gde23G 1 Reply Last reply
        4
        • raven-worxR raven-worx

          @gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:

          Is there another way to display the item grayed out without removing the Qt::ItemIsEnabled flag?

          return a desired color for Qt::ForegroundRole for the corresponding index in your data() implementation.

          gde23G Offline
          gde23G Offline
          gde23
          wrote on last edited by gde23
          #4

          @raven-worx
          Thanks, this works.
          Except for the border of the QCheckBoxes (for the cheackable items).
          They are still very bright. Do i have to set a style-sheet for those explicitly?

          raven-worxR 1 Reply Last reply
          0
          • gde23G gde23

            @raven-worx
            Thanks, this works.
            Except for the border of the QCheckBoxes (for the cheackable items).
            They are still very bright. Do i have to set a style-sheet for those explicitly?

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:

            Except for the border of the QCheckBoxes (for the cheackable items).
            They are still very bright. Do i have to set a style-sheet for those explicitly?

            you won't be able to style those explicitly, since you do not set the state to disabled.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            JonBJ 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @gde23 said in Gray out an item in TreeView without making it not selectable / right-clickable:

              Except for the border of the QCheckBoxes (for the cheackable items).
              They are still very bright. Do i have to set a style-sheet for those explicitly?

              you won't be able to style those explicitly, since you do not set the state to disabled.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @raven-worx
              Just OOI, how difficult/easy would it be to stick to right-click actually disabling the item and then recognise right-click-on-disabled-item (widget event filter??), so that you can toggle back to enabled?

              raven-worxR 1 Reply Last reply
              0
              • JonBJ JonB

                @raven-worx
                Just OOI, how difficult/easy would it be to stick to right-click actually disabling the item and then recognise right-click-on-disabled-item (widget event filter??), so that you can toggle back to enabled?

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @JonB said in Gray out an item in TreeView without making it not selectable / right-clickable:

                Just OOI, how difficult/easy would it be to stick to right-click actually disabling the item and then recognise right-click-on-disabled-item (widget event filter??), so that you can toggle back to enabled?

                yes it's possible to overrride the view's viewportEvent() and use indexAt().
                But this is then view dependent, and not implemented in the model anymore. Depends if this is desired.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                1

                • Login

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