Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why is the style so strange?
Qt 6.12 LTS is out! See what's new in the release blog

Why is the style so strange?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 687 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John Van
    wrote on last edited by John Van
    #1

    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
    动画.gif
    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.

    Chris KawaC 1 Reply Last reply
    0
    • J John Van

      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
      动画.gif
      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.

      Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #3

      @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 :unchecked style 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 1 Reply Last reply
      5
      • C Offline
        C Offline
        CPPUIX
        wrote on last edited by
        #2

        Hi,

        I'm not sure what your question is, but based on your code, this might provide an answer:

        QPushButton: changing icon via setStyleSheet

        1 Reply Last reply
        0
        • J John Van

          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
          动画.gif
          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.

          Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #3

          @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 :unchecked style 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 1 Reply Last reply
          5
          • J John Van has marked this topic as solved on
          • Chris KawaC Chris Kawa

            @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 :unchecked style 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 Offline
            J Offline
            John Van
            wrote on last edited by
            #4

            @Chris-Kawa Thank you so much.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved