Reload SystemPalette after setStyleSheet()

  • Hi,

    I my app you can set different styles, like a dark style, to more customize the look to your liking. To keep the look consistent for my QQuickWidgets I use the SystemPalette element, but the problem is that it doesn't update after I call setStyleSheet() (or setPalette()) in my code.

    How can I update the SystemPalette with a new pallette, so the style of my QQuickWidgets fits the overall theme?
    Do I actually need to create my own data structure and manually update it, or is there a easier way?

    Thanks for your help!

    Some code:

    TestWindowApp::TestWindowApp(QWidget *parent):QMainWindow(parent) {
    	connect(actionThemeDark, &QAction::triggered, this, [this]{;
    		QFile f(QString(RESOURCES_PATH)+"/styles/dark/style.qss");
    		if ( | QFile::Text)){
    		    setStyleSheet(QString(f.readAll()).arg(QString(RESOURCES_PATH)+"/styles/dark" ));
    		    emit onStyleChanged();//my custom emit
    		}else qDebug() << "Unable to set stylesheet, file not found!";
    	timelineQuickWidget->setSource(QUrl::fromLocalFile(RESOURCES_PATH "/qml/Timeline.qml"));


    import QtQuick 2.4
    Rectangle { 
    	SystemPalette { id: activePalette }
    	color: activePalette.window

  • SystemPalette corresponds to QGuiApplication::palette. Changing the palette of a window does not affect the application palette. Try changing the application palette. Notice also that setPalette(palette()) does not change the palette.

  • Not sure if this is the best approach, but it seems to work.
    I reload the QML file after the application palette has bean set.

    	connect(this, &TestWindowApp::onStyleChanged, this, [this]{
    		 //reload qml
    		timelineQuickWidget->setSource(QUrl::fromLocalFile(RESOURCES_PATH "/qml/Timeline.qml"));

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.