QQuickView change controls palette



  • I want to change controls color palette without style owerriding? How can I do this


  • Moderators

    Hi,

    I think you can do this by setting custom QPalette for your Application.



  • @ QGuiApplication app(argc, argv);

    QPalette customPalette;
    customPalette.setColor(QPalette::Window, QColor("red"));
    customPalette.setColor(QPalette::Background, QColor("red"));
    customPalette.setColor(QPalette::WindowText, QColor("red"));
    customPalette.setColor(QPalette::Foreground, QColor("red"));
    customPalette.setColor(QPalette::Base, QColor("red"));
    customPalette.setColor(QPalette::AlternateBase, QColor("red"));
    customPalette.setColor(QPalette::ToolTipBase, QColor("red"));
    customPalette.setColor(QPalette::ToolTipText, QColor("red"));
    customPalette.setColor(QPalette::Text, QColor("red"));
    customPalette.setColor(QPalette::Button, QColor("red"));
    customPalette.setColor(QPalette::ButtonText, QColor("red"));
    customPalette.setColor(QPalette::BrightText, QColor("red"));
    
    app.setPalette(customPalette);@
    

    Doesn't work (


  • Moderators

    I tried the following which works
    @
    QPalette customPalette(app.palette());
    customPalette.setColor(QPalette::ButtonText, QColor("red"));
    customPalette.setColor(QPalette::WindowText,QColor("yellow"));
    app.setPalette(customPalette);
    @

    and QML
    @
    Button {
    text: "Qt"
    }

    Label {
    text: "Hello world"
    }
    @

    Here the color of the text changes as per the palette but neither QPalette::Window/QPalette::Background/QPalette::Base/QPalette::Button worked for background of button for eg.


Log in to reply
 

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