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. [SOLVED]QTreeWidget setStyleSheet problem
QtWS25 Last Chance

[SOLVED]QTreeWidget setStyleSheet problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.5k 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
    tony_tang
    wrote on last edited by tony_tang
    #1

    I want to set the selected QTreeWidgetItem to a custom color, using the code below:
    setStyleSheet("QTreeWidget::item::selected{background-color: rgb(50, 50, 50)}");
    but it does not work very well: there is some other color on the left part of the QTreeWidgetItem.
    Is there any way to solve this?

    T 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi

      A QTreeWidget will show an arrow for items with children. to the left.
      Is it that area you area talking about ?

      Its not considered part of the item and will have the color for
      background-color for the whole TreeWidget.

      If you do not need a tree view, then maybe just use a listwidget where the item
      will take up all row. ?

      T 2 Replies Last reply
      0
      • mrjjM mrjj

        Hi

        A QTreeWidget will show an arrow for items with children. to the left.
        Is it that area you area talking about ?

        Its not considered part of the item and will have the color for
        background-color for the whole TreeWidget.

        If you do not need a tree view, then maybe just use a listwidget where the item
        will take up all row. ?

        T Offline
        T Offline
        tony_tang
        wrote on last edited by
        #3

        @mrjj Yes, it is the area to show an arrow for items with children.

        mrjjM 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi

          A QTreeWidget will show an arrow for items with children. to the left.
          Is it that area you area talking about ?

          Its not considered part of the item and will have the color for
          background-color for the whole TreeWidget.

          If you do not need a tree view, then maybe just use a listwidget where the item
          will take up all row. ?

          T Offline
          T Offline
          tony_tang
          wrote on last edited by
          #4

          @mrjj It is used to show the tree of scene, so I have to use the QTreeVidget.

          1 Reply Last reply
          0
          • T tony_tang

            @mrjj Yes, it is the area to show an arrow for items with children.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @tony_tang
            That area can be styled with QTreeView::branch
            have a look at
            https://forum.qt.io/topic/8034/changing-the-color-of-qtreeview-s-branches/2

            T 1 Reply Last reply
            0
            • mrjjM mrjj

              @tony_tang
              That area can be styled with QTreeView::branch
              have a look at
              https://forum.qt.io/topic/8034/changing-the-color-of-qtreeview-s-branches/2

              T Offline
              T Offline
              tony_tang
              wrote on last edited by
              #6

              @mrjj
              OK, I take a try, thank you very much.

              1 Reply Last reply
              0
              • T tony_tang

                I want to set the selected QTreeWidgetItem to a custom color, using the code below:
                setStyleSheet("QTreeWidget::item::selected{background-color: rgb(50, 50, 50)}");
                but it does not work very well: there is some other color on the left part of the QTreeWidgetItem.
                Is there any way to solve this?

                T Offline
                T Offline
                tony_tang
                wrote on last edited by tony_tang
                #7

                @tony_tang
                I solved the problem using this method:

                QPalette pal = palette();
                pal.setColor(QPalette::ColorRole::Highlight, QColor(50, 50, 50));
                setPalette(pal);

                mrjjM 1 Reply Last reply
                0
                • T tony_tang

                  @tony_tang
                  I solved the problem using this method:

                  QPalette pal = palette();
                  pal.setColor(QPalette::ColorRole::Highlight, QColor(50, 50, 50));
                  setPalette(pal);

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @tony_tang said:
                  Super!
                  Thank you for reporting back.

                  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