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 `QTreeWidgetItem::setBackground()` to all of the items associated with it.
QtWS25 Last Chance

How to `QTreeWidgetItem::setBackground()` to all of the items associated with it.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 3.1k 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.
  • T Offline
    T Offline
    thippu
    wrote on 6 Oct 2018, 06:39 last edited by thippu 10 Jun 2018, 06:49
    #1

    Hi,
    1)I have QTreeWidget and there are many QTreeWidgetItem attached to it.
    2) for each of the QTreeWidgetItem I want to set the background color, to do this I have done QTreeWidgetItem::setBackground(0,QColor(Qt::green)); , but problem is, it is changing the color only if the item gets selected. I want to set it to all. how to do it? : here the link to output the image .
    3) My final aim is to achieve this User interface: link to imaget please help me to achieve it.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 6 Oct 2018, 06:48 last edited by
      #2

      What items should be set to green? You can access the children via http://doc.qt.io/qt-5/qtreewidgetitem.html#child and all top level widgets with http://doc.qt.io/qt-5/qtreewidget.html#topLevelItem

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      T 1 Reply Last reply 6 Oct 2018, 06:52
      1
      • C Christian Ehrlicher
        6 Oct 2018, 06:48

        What items should be set to green? You can access the children via http://doc.qt.io/qt-5/qtreewidgetitem.html#child and all top level widgets with http://doc.qt.io/qt-5/qtreewidget.html#topLevelItem

        T Offline
        T Offline
        thippu
        wrote on 6 Oct 2018, 06:52 last edited by
        #3

        @Christian-Ehrlicher

        What items should be set to green?

        I want to set to all the sub-items of the alltoplevelItems without the selection item.

        J 1 Reply Last reply 6 Oct 2018, 14:56
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 6 Oct 2018, 07:33 last edited by
          #4

          So my proposed functions are exactly the ones you need for this.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 6 Oct 2018, 08:12 last edited by
            #5

            Hi
            just to make sure that you noticed
            setAlternatingRowColors(true);
            http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-prop

            that color every other row.
            and you can control the colors with

            setStyleSheet("alternate-background-color: yellow;background-color: red;");

            Im not sure if you just want alternating colors or something more fancy :)

            T 2 Replies Last reply 6 Oct 2018, 09:50
            2
            • M mrjj
              6 Oct 2018, 08:12

              Hi
              just to make sure that you noticed
              setAlternatingRowColors(true);
              http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-prop

              that color every other row.
              and you can control the colors with

              setStyleSheet("alternate-background-color: yellow;background-color: red;");

              Im not sure if you just want alternating colors or something more fancy :)

              T Offline
              T Offline
              thippu
              wrote on 6 Oct 2018, 09:50 last edited by
              #6

              @mrjj You are right.
              I was looking for this effect, Thank you so much.

              1 Reply Last reply
              0
              • M mrjj
                6 Oct 2018, 08:12

                Hi
                just to make sure that you noticed
                setAlternatingRowColors(true);
                http://doc.qt.io//qt-5/qabstractitemview.html#alternatingRowColors-prop

                that color every other row.
                and you can control the colors with

                setStyleSheet("alternate-background-color: yellow;background-color: red;");

                Im not sure if you just want alternating colors or something more fancy :)

                T Offline
                T Offline
                thippu
                wrote on 6 Oct 2018, 10:10 last edited by thippu 10 Jun 2018, 10:20
                #7

                @mrjj can we able to set it only to children? Or can top level be another color?

                M 1 Reply Last reply 6 Oct 2018, 13:07
                0
                • T thippu
                  6 Oct 2018, 10:10

                  @mrjj can we able to set it only to children? Or can top level be another color?

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 6 Oct 2018, 13:07 last edited by
                  #8

                  @thippu
                  hi
                  I dont think u can specify on which ones. its all or nothing.
                  In such case, the functions mr @Christian-Ehrlicher mentions can be used to handle your own coloring.
                  You can try set topcolor to new color after you have inserted it.
                  Im not sure if its possible to override with setBackground or if the alternate code will change it back.
                  You should test it.

                  T 1 Reply Last reply 6 Oct 2018, 13:18
                  0
                  • M mrjj
                    6 Oct 2018, 13:07

                    @thippu
                    hi
                    I dont think u can specify on which ones. its all or nothing.
                    In such case, the functions mr @Christian-Ehrlicher mentions can be used to handle your own coloring.
                    You can try set topcolor to new color after you have inserted it.
                    Im not sure if its possible to override with setBackground or if the alternate code will change it back.
                    You should test it.

                    T Offline
                    T Offline
                    thippu
                    wrote on 6 Oct 2018, 13:18 last edited by
                    #9

                    @mrjj okay bro, I will try.

                    1 Reply Last reply
                    1
                    • T thippu
                      6 Oct 2018, 06:52

                      @Christian-Ehrlicher

                      What items should be set to green?

                      I want to set to all the sub-items of the alltoplevelItems without the selection item.

                      J Offline
                      J Offline
                      JonB
                      wrote on 6 Oct 2018, 14:56 last edited by JonB 10 Jun 2018, 15:01
                      #10

                      @thippu

                      I want to set to all the sub-items of the alltoplevelItems without the selection item.

                      I'll just throw in that assuming you can address the items with a selector (e.g. QTreeWidget > QTreeWidgetItem == top-level only, :selected == selected only), a stylesheet rule (or two) could allow you to do this in one go without iterating anything....

                      T 1 Reply Last reply 8 Oct 2018, 09:30
                      1
                      • J JonB
                        6 Oct 2018, 14:56

                        @thippu

                        I want to set to all the sub-items of the alltoplevelItems without the selection item.

                        I'll just throw in that assuming you can address the items with a selector (e.g. QTreeWidget > QTreeWidgetItem == top-level only, :selected == selected only), a stylesheet rule (or two) could allow you to do this in one go without iterating anything....

                        T Offline
                        T Offline
                        thippu
                        wrote on 8 Oct 2018, 09:30 last edited by
                        #11

                        @JonB Thank you. Sure I will try.

                        1 Reply Last reply
                        0

                        9/11

                        6 Oct 2018, 13:18

                        • Login

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