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
QtWS25 Last Chance

QTreeview Apply delegate based on specific Condition

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 370 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.
  • DonCoderD Offline
    DonCoderD Offline
    DonCoder
    wrote on 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      • DonCoderD Offline
        DonCoderD Offline
        DonCoder
        wrote on 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

        mrjjM 1 Reply Last reply
        0
        • DonCoderD DonCoder

          @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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on 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?

          DonCoderD 1 Reply Last reply
          2
          • mrjjM mrjj

            @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?

            DonCoderD Offline
            DonCoderD Offline
            DonCoder
            wrote on last edited by
            #5

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

            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