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); button.setStyleSheet( "QPushButton:hover {" " background: grey;" " border-radius: 50%;" "}" ); window.show(); return app.exec(); }
When executing the example above I get a button with a circle-like border, as expected.
But when doing the same thing with a larger button I get no circle-like border even though
border-radius: 50%
should create one.
It seems like Qt is using pixel values even though I am using percentages. Is it possible that Qt does not support percentage values?
-
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); button.setStyleSheet( "QPushButton:hover {" " background: grey;" " border-radius: 50%;" "}" ); window.show(); return app.exec(); }
When executing the example above I get a button with a circle-like border, as expected.
But when doing the same thing with a larger button I get no circle-like border even though
border-radius: 50%
should create one.
It seems like Qt is using pixel values even though I am using percentages. Is it possible that Qt does not support percentage values?
-
@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.