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. backgournd color only takes effect on items
Qt 6.11 is out! See what's new in the release blog

backgournd color only takes effect on items

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    m.f.d
    wrote on last edited by
    #1

    Hello, I want to set diffenrent background color for different rows. It seems the background color doesn't take effect on branch icon and indentation area at left side,while there are no such issues from the similar images from google. The test environment is windows11 qt 5.15.4 and visual studio2022 with qt extension.
    Here is the test code:

            QTreeView* treeView = new QTreeView(this);
    	QStandardItemModel* model = new QStandardItemModel(treeView);
    	QStandardItem* item1 = new QStandardItem("node1");
    	QStandardItem* item2 = new QStandardItem("node2");
    	treeView->setStyleSheet(styleSheet);
    	treeView->setModel(model);
    	model->appendRow(item1);
    	item1->appendRow(item2);
            treeView->setAlternatingRowColors(true);
    	QString styleSheet = "QTreeView{alternate-background-color: #ff0000;}";
    

    9f8e8026-0fc3-4094-9815-427bf449982c-图片.png
    Anyone can help?

    Pl45m4P 1 Reply Last reply
    0
    • M m.f.d

      Hello, I want to set diffenrent background color for different rows. It seems the background color doesn't take effect on branch icon and indentation area at left side,while there are no such issues from the similar images from google. The test environment is windows11 qt 5.15.4 and visual studio2022 with qt extension.
      Here is the test code:

              QTreeView* treeView = new QTreeView(this);
      	QStandardItemModel* model = new QStandardItemModel(treeView);
      	QStandardItem* item1 = new QStandardItem("node1");
      	QStandardItem* item2 = new QStandardItem("node2");
      	treeView->setStyleSheet(styleSheet);
      	treeView->setModel(model);
      	model->appendRow(item1);
      	item1->appendRow(item2);
              treeView->setAlternatingRowColors(true);
      	QString styleSheet = "QTreeView{alternate-background-color: #ff0000;}";
      

      9f8e8026-0fc3-4094-9815-427bf449982c-图片.png
      Anyone can help?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @m-f-d

      How does it look if you create multiple items on the same level of your tree? Do they have alternating colors then?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      Christian EhrlicherC M 2 Replies Last reply
      0
      • Pl45m4P Pl45m4

        @m-f-d

        How does it look if you create multiple items on the same level of your tree? Do they have alternating colors then?

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        It's a style thing. See SH_ItemView_ShowDecorationSelected. For fusion it's enabled, for windows only when it is a QListView

        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
        • Pl45m4P Pl45m4

          @m-f-d

          How does it look if you create multiple items on the same level of your tree? Do they have alternating colors then?

          M Offline
          M Offline
          m.f.d
          wrote on last edited by
          #4

          @Pl45m4 Sure, but only for items, branch icons are still white background.

          Christian EhrlicherC 1 Reply Last reply
          0
          • M m.f.d

            @Pl45m4 Sure, but only for items, branch icons are still white background.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @m-f-d said in backgournd color only takes effect on items:

            but only for items, branch icons are still white background.

            Ignoring me helps for sure...

            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
            0

            • Login

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