Congratulations to our 2022 Qt Champions!

Unexpected behavior using percentage in stylesheet.

  • Hello,

    I hope this is not an obvious mistake on my end but I was using a stylesheet for a QPushButton and got (in my opinion) unexpected behavior. Here is a little demo project.

    #include <QApplication>
    #include <QPushButton>
    #include <QWidget>
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        QWidget window;
        window.setFixedSize(210, 210);
        QPushButton button(&window);
        button.setGeometry(5, 5, 100, 100);
            "QPushButton:hover {"
            "  background: grey;"
            "  border-radius: 50%;"
        return app.exec();

    When executing the example above I get a button with a circle-like border, as expected.
    0_1525857998061_Screenshot (1).png

    But when doing the same thing with a larger button I get no circle-like border even though border-radius: 50% should create one.
    0_1525858504958_Screenshot (2).png

    It seems like Qt is using pixel values even though I am using percentages. Is it possible that Qt does not support percentage values?

  • Lifetime Qt Champion

    I dont think it likes % as you suspect.
    I never seen a sample with it , nor did it ever work for me.

  • @mrjj
    And what's the next best option? I would like to have a round border around my button. I thought about using a placefiller and then replacing it after reading the css file but it feels wrong.

  • Lifetime Qt Champion


    Depends on what real goal is ?
    If to have a round button, a custom control would do it nicely.

Log in to reply