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. QTreeview Apply delegate based on specific Condition
Forum Update on Monday, May 27th 2025

QTreeview Apply delegate based on specific Condition

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 388 Views
  • 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.
  • D Offline
    D Offline
    DonCoder
    wrote on 11 Feb 2021, 17:37 last edited by
    #1

    I am working on a Qtreeview. I have a requirement. For particular nodes i want to apply different styling based on an attributes value i save in nodeData. I can fetch that attribute value using a userRole. Now how to apply stying for the specific nodes.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 11 Feb 2021, 18:10 last edited by
      #2

      Hi
      https://doc.qt.io/qt-5/qabstractitemview.html#setItemDelegateForColumn
      If you mean to apply different delegates based on the UserRole

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DonCoder
        wrote on 11 Feb 2021, 19:27 last edited by
        #3

        @mrjj Okay i think i can make use of setItemDelegateForRow(rowNo,MyDelegate*);
        But which is best place to set this ? . DO i need to explicitly check each model index or can i use model data() function to set ? If so please share a code snippet

        M 1 Reply Last reply 11 Feb 2021, 19:32
        0
        • D DonCoder
          11 Feb 2021, 19:27

          @mrjj Okay i think i can make use of setItemDelegateForRow(rowNo,MyDelegate*);
          But which is best place to set this ? . DO i need to explicitly check each model index or can i use model data() function to set ? If so please share a code snippet

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 11 Feb 2021, 19:32 last edited by
          #4

          @DonCoder
          As far as I know we can only set a delegate with the setItemXX functions.

          But im wondering. Could you not just have one Delegate and it reads
          the UserRole and then paint the cell accordingly?

          D 1 Reply Last reply 11 Feb 2021, 19:55
          2
          • M mrjj
            11 Feb 2021, 19:32

            @DonCoder
            As far as I know we can only set a delegate with the setItemXX functions.

            But im wondering. Could you not just have one Delegate and it reads
            the UserRole and then paint the cell accordingly?

            D Offline
            D Offline
            DonCoder
            wrote on 11 Feb 2021, 19:55 last edited by
            #5

            @mrjj I totally agree with you. Thanks It answers my question

            1 Reply Last reply
            0

            1/5

            11 Feb 2021, 17:37

            • Login

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