Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListWidgetItem setForeground does not work anymore
Qt 6.12 LTS is out! See what's new in the release blog

QListWidgetItem setForeground does not work anymore

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.7k Views 2 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.
  • W Offline
    W Offline
    WWebber
    wrote on last edited by
    #1

    Re: QListWidgetItem setForeground does not work with global stylesheet

    I updated to QT 5.15.2 and now I experience the same problem! Is there a workaround, that tree widget items ignore this stylesheet? I need the stylesheet for other reasond. The older QT version 5.12.x worked correctly for this case?!

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @WWebber said in QListWidgetItem setForeground does not work anymore:

      The brush from the treeitem holds no solid color, although displayed in solid black.

      I don't understand what you're trying to tell us. Please provide a minimal, compileable example.

      W Offline
      W Offline
      WWebber
      wrote on last edited by
      #7

      @Christian-Ehrlicher
      Actually the problem is fixed.
      The anomaly between 5.12 and 5.15 was, that the default brush the tree-item returned, did not hold a solid brush. But I did not further investigate, what exactly it held, I simply set it. Schedule is tight - Thx anyway

      1 Reply Last reply
      0
      • W WWebber

        Re: QListWidgetItem setForeground does not work with global stylesheet

        I updated to QT 5.15.2 and now I experience the same problem! Is there a workaround, that tree widget items ignore this stylesheet? I need the stylesheet for other reasond. The older QT version 5.12.x worked correctly for this case?!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @WWebber
        You would have to state what your exact issue is, because I see many things discussed in that thread.

        W 1 Reply Last reply
        0
        • JonBJ JonB

          @WWebber
          You would have to state what your exact issue is, because I see many things discussed in that thread.

          W Offline
          W Offline
          WWebber
          wrote on last edited by
          #3

          @JonB
          To put it short, the widgetItem->setForeground() is not working anymore (in V5.12 it worked but in V5.15 it does not - same code). Other than a user wrote it also does not work without a stylesheet on the tree-control. Everything else in the treeview like icons, fonts and checkboxes are ok.

          Christian EhrlicherC 1 Reply Last reply
          0
          • W WWebber

            @JonB
            To put it short, the widgetItem->setForeground() is not working anymore (in V5.12 it worked but in V5.15 it does not - same code). Other than a user wrote it also does not work without a stylesheet on the tree-control. Everything else in the treeview like icons, fonts and checkboxes are ok.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Works fine for me, please provide a minimal, compilable example and the OS and style you're using

            int main(int argc, char* argv[])
            {
                QApplication app(argc, argv);
                QTableWidget tw;
                tw.setRowCount(1);
                tw.setColumnCount(1);
                auto item = new QTableWidgetItem;
                item->setText("Hello");
                item->setForeground(QBrush(Qt::red));
                tw.setItem(0,0,item);
                tw.show();
                app.exec();
            }
            

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

            W 1 Reply Last reply
            3
            • Christian EhrlicherC Christian Ehrlicher

              Works fine for me, please provide a minimal, compilable example and the OS and style you're using

              int main(int argc, char* argv[])
              {
                  QApplication app(argc, argv);
                  QTableWidget tw;
                  tw.setRowCount(1);
                  tw.setColumnCount(1);
                  auto item = new QTableWidgetItem;
                  item->setText("Hello");
                  item->setForeground(QBrush(Qt::red));
                  tw.setItem(0,0,item);
                  tw.show();
                  app.exec();
              }
              
              W Offline
              W Offline
              WWebber
              wrote on last edited by
              #5

              @Christian-Ehrlicher

              well.. the problem is on a different place:

              QBrush b = item->foreground(0);
              b.setColor(Qt::red);
              item->setForeground(0, b);
              

              The brush from the treeitem holds no solid color, although displayed in solid black.

              Christian EhrlicherC 1 Reply Last reply
              0
              • W WWebber

                @Christian-Ehrlicher

                well.. the problem is on a different place:

                QBrush b = item->foreground(0);
                b.setColor(Qt::red);
                item->setForeground(0, b);
                

                The brush from the treeitem holds no solid color, although displayed in solid black.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @WWebber said in QListWidgetItem setForeground does not work anymore:

                The brush from the treeitem holds no solid color, although displayed in solid black.

                I don't understand what you're trying to tell us. Please provide a minimal, compileable example.

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

                W 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  @WWebber said in QListWidgetItem setForeground does not work anymore:

                  The brush from the treeitem holds no solid color, although displayed in solid black.

                  I don't understand what you're trying to tell us. Please provide a minimal, compileable example.

                  W Offline
                  W Offline
                  WWebber
                  wrote on last edited by
                  #7

                  @Christian-Ehrlicher
                  Actually the problem is fixed.
                  The anomaly between 5.12 and 5.15 was, that the default brush the tree-item returned, did not hold a solid brush. But I did not further investigate, what exactly it held, I simply set it. Schedule is tight - Thx anyway

                  1 Reply Last reply
                  0
                  • W WWebber has marked this topic as solved on

                  • Login

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