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. Problem with button colors when changing palette.
Forum Updated to NodeBB v4.3 + New Features

Problem with button colors when changing palette.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • N Offline
    N Offline
    nejatafshar
    wrote on last edited by
    #1

    When application palette is changed before a widget is shown all color roles are applied properly. But if you change app palette after showing the widget, the Button role color does not get updated. For instance in the following code color of push button remains unchanged:

    #include <QApplication>
    #include <QPushButton>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        qApp->setStyle("fusion");
    
        QPalette palette;
        palette.setColor(QPalette::Button, Qt::black);
    
        QPushButton pb;
        pb.show();
    
        for(int i=0;i<1000;i++)
            qApp->processEvents(QEventLoop::AllEvents);
    
        qApp->setPalette(palette);
    
        return a.exec();
    }
    

    I am using Qt 5.8. This was not the case in Qt 5.7. I have tested the code in Windows and Linux on different PCs, both have this problem. It seems that the problem is only for Button role and other roles are changed properly.

    Is there any workaround to set a color for button role in the above example?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      Please check Qt bug tracker - if it is not reported please file a bug report.

      In your example code you are calling processEvents() before even loop is started (in exec()), so it might skew the results. Does it also not work when palette is changed after even loop is started?

      (Z(:^

      N 1 Reply Last reply
      0
      • sierdzioS sierdzio

        Please check Qt bug tracker - if it is not reported please file a bug report.

        In your example code you are calling processEvents() before even loop is started (in exec()), so it might skew the results. Does it also not work when palette is changed after even loop is started?

        N Offline
        N Offline
        nejatafshar
        wrote on last edited by
        #3

        @sierdzio I have reported this as a bug: https://bugreports.qt.io/browse/QTBUG-59101?filter=-2

        The problem exists if palette is changed after starting event loop. Actually i have narrowed down the problem to show in a simple way when and how it occurs. I know it's a bug, I am looking for a workaround if possible.

        1 Reply Last reply
        2

        • Login

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