Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Unexpected behavior using percentage in stylesheet.

    General and Desktop
    2
    4
    850
    Loading More Posts
    • 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
      jsmolka last edited by

      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.
      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?

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @jsmolka last edited by mrjj

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

        1 Reply Last reply Reply Quote 1
        • J
          jsmolka last edited by

          @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.

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @jsmolka last edited by

            @jsmolka

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post