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

QCheckBox style is different in Qt Creator using same stylesheet.



  • I'm using the same stylesheet when running my tool within Qt Creator but the QCheckBox style appears different.
    On the left is the style outside of Qt Creator; the right shows the default stype when the tool is started within Qt Creator.
    I like the style on the right and would like to keep it, but I can't make it happen.
    ecfaca39-57a8-4a8c-95de-a98fa0a4dda2-image.png
    I would like the QCheckBoxes to have the same background as the frame they are in, so the QSS looks like this:

    /* All checkboxes in frame */
    #selectAlertsTypeFrame QCheckBox {
    background-color: lightblue;
    }

    Is there a way I can make the QCheckBoxes have the same white background as when the tool is started within Qt Creator?


  • Lifetime Qt Champion

    This looks like the underlying style is different - left looks like windows style, right fusion



  • When you run the program "without" Qt creator, do you mean you deployed the dlls with the exe and run the exe directly?
    Looks like you didn't copy the styles plugin folder with qwindowsvistastyle.dll, so it is using xp style.



  • @Christian-Ehrlicher Both are running on the same machine, which is Windows 10 vs2019-64



  • @Bonnie Correct, ran from the command line in a different location.

    OMG, that was it....I didn't have the styles library.
    We use the opensource version and build it on a bunch of platforms, have been for a number of years, and we have never copied over the qwindowsvistastyle.dll library for windows.

    Do you know if there is a way I can just set that QCheckBox style using my QSS stylesheet?
    I would like it to look that way on Mac and Linux too, I just want the white background within the square. :)



  • @knightspace Use a QStyle: a.setStyle("fusion"); or a.setStyle("windows");



  • @eyllanesc Thanks, I'll give it a go.



  • Here it is....it's close.
    ui->showNotesCheckBox->setStyle(QStyleFactory::create("Fusion"));
    0ba99369-5b2a-4f01-a453-7a7360ec9417-image.png

    Still can't get the background of the actual checkbox square box to be white, unless I use the qwindowsvistastyle.dll library...which is don't really want to do since I want it the same on all platforms.

    P.S. I'm watching my own post now, so I should get notified of replies.



  • @knightspace

    1. If you want the whole ui same on all platforms, not only the checkbox, then you should set the style to the application, not to the checkbox, as @eyllanesc posted (a is the QApplication in main.cpp)
    2. If you are using fusion style as the application style, then you don't need to set the checkbox's background color in qss, it should be just like what you want.(Unless it would inherit the background color from some parent widget, in that case you should modify the parent qss to make it not apply to the checkboxes.)


  • @Bonnie Thanks, but I'd like the style the stay as it is on the platforms, I really just want the little checkbox square to be white....picky right! :)


Log in to reply