Why is the style so strange?
-
Hello,
This is the code.QApplication a(argc, argv); QPushButton* button = new QPushButton("Click Me"); button->setStyleSheet("QPushButton:checked{ background: red; }QPushButton:unchecked{ background: green; }"); button->setCheckable(true); button->setChecked(true); button->show(); return a.exec();and this is the button

I was confused.the qt version is5.14.2,the console print("QWindowsWindow::setGeometry: Unable to set geometry 93x28+960+450 (frame: 111x75+951+412) on QWidgetWindow/"QPushButtonClassWindow" on "\.\DISPLAY1". Resulting geometry: 152x28+960+450 (frame: 170x75+951+412) margins: 9, 38, 9, 9)")
Thanks. -
Hello,
This is the code.QApplication a(argc, argv); QPushButton* button = new QPushButton("Click Me"); button->setStyleSheet("QPushButton:checked{ background: red; }QPushButton:unchecked{ background: green; }"); button->setCheckable(true); button->setChecked(true); button->show(); return a.exec();and this is the button

I was confused.the qt version is5.14.2,the console print("QWindowsWindow::setGeometry: Unable to set geometry 93x28+960+450 (frame: 111x75+951+412) on QWidgetWindow/"QPushButtonClassWindow" on "\.\DISPLAY1". Resulting geometry: 152x28+960+450 (frame: 170x75+951+412) margins: 9, 38, 9, 9)")
Thanks.@John-Van Most of the time setting any qss property disables the native style entirely, but for some properties that the native style can handle Qt will try to use those. This is the case with a button background. The grid-like pattern you see is part of the native checked style. You can disable native style entirely by setting some other property, e.g. a border.
Second thing is that the
:uncheckedstyle doesn't seem to apply to all types of widgets. It doesn't work for buttons. To style unchecked button just don't specify the state, so combining those two things you can style it like this:"QPushButton { border:none; background: green; } QPushButton:checked { background: red; }"As for the message - it's unrelated to the styling. It means that Qt calculated the size for the button and tried to create a window of that size, but it was smaller than a minimum allowed window size, so the button was enlarged to meet that minimum. Native windows have a minimum size dictated by the style of the frame - whether it has close, min/max buttons and an icon. It's safe to ignore this message. If you want to avoid it make sure you resize your widget to above that minimum before you show the widget, or change the window flags not to include those frame elements that dictate minimum size if you don't need them.
-
Hi,
I'm not sure what your question is, but based on your code, this might provide an answer:
-
Hello,
This is the code.QApplication a(argc, argv); QPushButton* button = new QPushButton("Click Me"); button->setStyleSheet("QPushButton:checked{ background: red; }QPushButton:unchecked{ background: green; }"); button->setCheckable(true); button->setChecked(true); button->show(); return a.exec();and this is the button

I was confused.the qt version is5.14.2,the console print("QWindowsWindow::setGeometry: Unable to set geometry 93x28+960+450 (frame: 111x75+951+412) on QWidgetWindow/"QPushButtonClassWindow" on "\.\DISPLAY1". Resulting geometry: 152x28+960+450 (frame: 170x75+951+412) margins: 9, 38, 9, 9)")
Thanks.@John-Van Most of the time setting any qss property disables the native style entirely, but for some properties that the native style can handle Qt will try to use those. This is the case with a button background. The grid-like pattern you see is part of the native checked style. You can disable native style entirely by setting some other property, e.g. a border.
Second thing is that the
:uncheckedstyle doesn't seem to apply to all types of widgets. It doesn't work for buttons. To style unchecked button just don't specify the state, so combining those two things you can style it like this:"QPushButton { border:none; background: green; } QPushButton:checked { background: red; }"As for the message - it's unrelated to the styling. It means that Qt calculated the size for the button and tried to create a window of that size, but it was smaller than a minimum allowed window size, so the button was enlarged to meet that minimum. Native windows have a minimum size dictated by the style of the frame - whether it has close, min/max buttons and an icon. It's safe to ignore this message. If you want to avoid it make sure you resize your widget to above that minimum before you show the widget, or change the window flags not to include those frame elements that dictate minimum size if you don't need them.
-
J John Van has marked this topic as solved on
-
@John-Van Most of the time setting any qss property disables the native style entirely, but for some properties that the native style can handle Qt will try to use those. This is the case with a button background. The grid-like pattern you see is part of the native checked style. You can disable native style entirely by setting some other property, e.g. a border.
Second thing is that the
:uncheckedstyle doesn't seem to apply to all types of widgets. It doesn't work for buttons. To style unchecked button just don't specify the state, so combining those two things you can style it like this:"QPushButton { border:none; background: green; } QPushButton:checked { background: red; }"As for the message - it's unrelated to the styling. It means that Qt calculated the size for the button and tried to create a window of that size, but it was smaller than a minimum allowed window size, so the button was enlarged to meet that minimum. Native windows have a minimum size dictated by the style of the frame - whether it has close, min/max buttons and an icon. It's safe to ignore this message. If you want to avoid it make sure you resize your widget to above that minimum before you show the widget, or change the window flags not to include those frame elements that dictate minimum size if you don't need them.
@Chris-Kawa Thank you so much.