Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unexpected behavior using percentage in stylesheet.
Forum Updated to NodeBB v4.3 + New Features

Unexpected behavior using percentage in stylesheet.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.4k Views 1 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
    jsmolka
    wrote on last edited by
    #1

    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?

    mrjjM 1 Reply Last reply
    0
    • J jsmolka

      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?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @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
      1
      • J Offline
        J Offline
        jsmolka
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • J jsmolka

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          • Login

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