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. Is there a way to style the root item in a QTreeWidget using stylesheets?
QtWS25 Last Chance

Is there a way to style the root item in a QTreeWidget using stylesheets?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 4.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    I'm working on a new user interface that has - among other things - a few QTreeWidgets. To make it look like the rest of my application, I'm trying to apply a custom stylesheet to it. This works for the most part, however, I cannot figure out, how to change the formatting of the root item in the tree (the one that is typcially set in a gray bar on top).

    QTreeWidget:item 
    {
       background-color...
    }
    

    only works for the items below the root item. I'd be very grateful for any hint!

    Thanks!

    A 1 Reply Last reply
    0
    • ? A Former User

      I'm working on a new user interface that has - among other things - a few QTreeWidgets. To make it look like the rest of my application, I'm trying to apply a custom stylesheet to it. This works for the most part, however, I cannot figure out, how to change the formatting of the root item in the tree (the one that is typcially set in a gray bar on top).

      QTreeWidget:item 
      {
         background-color...
      }
      

      only works for the items below the root item. I'd be very grateful for any hint!

      Thanks!

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @tobiSF Do you mean the header for the tree? Or the root item? The root item should be the same as all the other items. I would need to test it but it should be affected by your item stylesheet.

      Can you share a small code example in how you build your tree?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        It's probably not the root item, it's more the column headline, like 'Folders' in this example. This is not my tree but it's close enough to illustrate what I'm doing.

        Example QTreeWidget

        The code is very simple, the tree in question is for a settings dialog and right now, there's only one entry besides the headline:

        QTreeWidget* pTree = new QTreeWidget();
        pTree->setColumnCount(1);
        pTree->addItem(QTreeWidgetItem(0, QStringList("User Information"));
        

        That's pretty much it, I don't have access to my actual code right now.

        A 1 Reply Last reply
        0
        • ? A Former User

          It's probably not the root item, it's more the column headline, like 'Folders' in this example. This is not my tree but it's close enough to illustrate what I'm doing.

          Example QTreeWidget

          The code is very simple, the tree in question is for a settings dialog and right now, there's only one entry besides the headline:

          QTreeWidget* pTree = new QTreeWidget();
          pTree->setColumnCount(1);
          pTree->addItem(QTreeWidgetItem(0, QStringList("User Information"));
          

          That's pretty much it, I don't have access to my actual code right now.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @tobiSF Ok that makes sense... So the control you want is called a QHeaderView. So you will need to style that separately from the QTreeView::item that you are changing.

          Here is an example from Qt docs:

          QHeaderView::section {
              background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                                                stop:0 #616161, stop: 0.5 #505050,
                                                stop: 0.6 #434343, stop:1 #656565);
              color: white;
              padding-left: 4px;
              border: 1px solid #6c6c6c;
          }
          
          QHeaderView::section:checked
          {
              background-color: red;
          }
          
          /* style the sort indicator */
          QHeaderView::down-arrow {
              image: url(down_arrow.png);
          }
          
          QHeaderView::up-arrow {
              image: url(up_arrow.png);
          }
          

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          3
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @ambershark thanks a lot, pointing out the right control was exactly what I needed. Do you know if there is a more comprehensive documentation of the entire QSS realm than what's on the Qt website?

            A 1 Reply Last reply
            0
            • ? A Former User

              @ambershark thanks a lot, pointing out the right control was exactly what I needed. Do you know if there is a more comprehensive documentation of the entire QSS realm than what's on the Qt website?

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @tobiSF I wish, I haven't found one. I just use the docs from Qt.. There are a few good pages that show everything. I found that header view one in the docs as I mentioned.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              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