Search code examples
qtqt4stylesheetqtstylesheetsqpushbutton

QPushButton dimensions change when Stylesheet is apllied


When I apply a style sheet on QPushButton its dimensions change. This is my style sheet declaration.

 QPushButton { 
   background-color: rgb(175, 187, 199);
   color: black;
   border-width: 1px;
   border-top: 1px solid white;
   border-left: 1px solid white;
   border-right: 1px solid grey;
   border-bottom: 1px solid grey;
   border-style: solid;
   border-radius: 5;
   padding: 3px; 
   padding-left: 5px; 
   padding-right: 5px;
   font: 16px;
   font-weight: bold;
}

Image - Before applying style sheet

Image - After applying style sheet

How to keep the original button size?


Solution

  • Based on comment below question: Try add qualifier:

    MyDialog QPushButton { 
       background-color: rgb(175, 187, 199);
       color: black;
       border-width: 1px;
       border-top: 1px solid white;
       border-left: 1px solid white;
       border-right: 1px solid grey;
       border-bottom: 1px solid grey;
       border-style: solid;
       border-radius: 5;
       padding: 3px; 
       padding-left: 5px; 
       padding-right: 5px;
       font: 16px;
       font-weight: bold;
    }
    

    This should be merged with default style sheet (not override the whole thing) and work only on buttons you need to alter.

    See documentation.