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. How to set 3 color in one column of QTreeWidgetItem?
Forum Updated to NodeBB v4.3 + New Features

How to set 3 color in one column of QTreeWidgetItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 2.6k 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #2

    use setData function with either decoration role or background role by passing the appropriate QColor value.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    1 Reply Last reply
    1
    • O Offline
      O Offline
      opengpu2
      wrote on last edited by
      #3

      i want multiple color in just 1 column....

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #4

        eg. cut the column in 2 half part , and each part fill with different color

        1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #5

          anyone can help? thx

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

            custom delegate!
            you need to reimplement QStyledItemDelegate::paint

            "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
            1
            • O Offline
              O Offline
              opengpu2
              wrote on last edited by
              #7

              can i customize a QPixmap, and set this QPixmap by setIcon to that column?

              VRoninV 1 Reply Last reply
              0
              • O opengpu2

                can i customize a QPixmap, and set this QPixmap by setIcon to that column?

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #8

                @opengpu2 I would not go down this path. At least I'd set it as Qt::BackgroundRole but, again, a custom delegate is the right solution.

                Are the background colors dependant on the content of the cell?

                "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

                O 2 Replies Last reply
                1
                • VRoninV VRonin

                  @opengpu2 I would not go down this path. At least I'd set it as Qt::BackgroundRole but, again, a custom delegate is the right solution.

                  Are the background colors dependant on the content of the cell?

                  O Offline
                  O Offline
                  opengpu2
                  wrote on last edited by
                  #9

                  @VRonin yes, depend on the content, and the number of colors are not the same, maybe 1,2 ,3, etc..

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    @opengpu2 I would not go down this path. At least I'd set it as Qt::BackgroundRole but, again, a custom delegate is the right solution.

                    Are the background colors dependant on the content of the cell?

                    O Offline
                    O Offline
                    opengpu2
                    wrote on last edited by
                    #10

                    @VRonin if i use delegate, actually just for this column in order to make it consist of colors, and i donot want to make any change to the other columns

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

                      ok, if you describe how to determine the number of colours, how much space each colour should take in the cell and how to determine the colour itself (I mean red, blue, yellow, etc.). I can draft a basic delegate up

                      "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

                      O 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        ok, if you describe how to determine the number of colours, how much space each colour should take in the cell and how to determine the colour itself (I mean red, blue, yellow, etc.). I can draft a basic delegate up

                        O Offline
                        O Offline
                        opengpu2
                        wrote on last edited by
                        #12

                        @VRonin that's easy in my situation, just make the space for each color equal.

                        VRoninV 1 Reply Last reply
                        0
                        • O opengpu2

                          @VRonin that's easy in my situation, just make the space for each color equal.

                          VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #13

                          @opengpu2 Yes but how do I determine which colors to use and what cells should have the double color?

                          "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