Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem changing StyleSheet at runtime with Qt 12.4 an 13.0



  • Hi all,

    I have a problem with StyleSheets. I was using Qt 12.3 on Windows 10 and Mint Linux (both 64 bit) with two customized stylesheet (dark and light). The StyleSheets are ok, both has been working since Qt 4.8.

    I can change this stylesheet in my application at runtime. And everything was fine.
    Now with 12.4 and 13 this does not work any more. When I start my app with the dark theme or with the light theme the appearance is ok. But when I change the stylesheet, just the MainWindow is beeing updated but not the other widgets in the MainWindow.
    I just called

    setStyleSheet( myStyleSheet ); 
    

    I made it work again with a workaround by calling updateStyleSheet for each widget in the mainwindow, but this is very slow.

    void MainWindow::changeStyleSheet( const QByteArray& styleSheet )
    {
        setStyleSheet( myStyleSheet ); 
        updateStyleSheet( this );
    }
    
    void MainWindow::updateStyleSheet( QWidget* widget )
    {
        if( widget )
        {
            widget->style()->unpolish( widget );
            widget->style()->polish( widget );
            widget->update();
    
            foreach( QObject* o, widget->children() )
            {
                QWidget* w = qobject_cast< QWidget* >( o );
                if( w )
                {
                    updateStyleSheet( w );
                }
            }
        }
    }
    

    Any ideas? Or is the a bug?

    regards
    Oliver


  • Moderators

    Check Qt bug tracker (https://bugreports.qt.io) from what you write it looks like a bug (even more, a regression).



  • I reported to the Bug tracker.
    https://bugreports.qt.io/browse/QTBUG-77006


Log in to reply