Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.
-
wrote on 31 May 2022, 13:35 last edited by AlexNevskiy
Hello all!
Imagine that I want all buttons in my prog to have a nice gradient look. And I use a global app stylesheet for this purpose. But something not understandable is going on when I'm trying to control the buttons' background through it.
If I have buttons in horizontal layout with spacer, and set the next app stylesheet
QPushButton { background: lightblue; border: 1px solid blue; /* need for full overpainting */ }
then widths of all of the buttons flow away, and buttons with a little text become very small.
If I add a line to the stylesheet:
min-width: 80px;
or, just
width: 80px;
then buttons with small text become ok, but buttons with long text not expand and their texts are partially hidden.
So, how to change background for all buttons and not to break its dimensions?
-
wrote on 31 May 2022, 14:14 last edited by
Perhaps add some padding. E.g. padding: 5px;
-
wrote on 31 May 2022, 14:50 last edited by
Or perhaps a large maximum width.
-
wrote on 31 May 2022, 14:50 last edited by
@Tink I tried paddings, it didn't help me.
-
wrote on 31 May 2022, 14:51 last edited by AlexNevskiy
@Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
Or perhaps a large maximum width.
then all the buttons will be unnecessary large
-
@Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
Or perhaps a large maximum width.
then all the buttons will be unnecessary large
wrote on 31 May 2022, 14:54 last edited by@AlexNevskiy hmm... perhaps you need to change the sizePolicy?
-
wrote on 31 May 2022, 14:56 last edited by
So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.
-
@AlexNevskiy hmm... perhaps you need to change the sizePolicy?
wrote on 31 May 2022, 14:59 last edited by@Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
@AlexNevskiy hmm... perhaps you need to change the sizePolicy?
Which policy will make it work?
-
So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.
wrote on 31 May 2022, 15:00 last edited by@AlexNevskiy said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
So, I have found some sort of solution. Just need to set width of expanding spacer to minimum (0 for example). And it works some how.
Makes sense.
-
@Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
@AlexNevskiy hmm... perhaps you need to change the sizePolicy?
Which policy will make it work?
wrote on 31 May 2022, 15:03 last edited by@AlexNevskiy said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
@Tink said in Changing app's QPushButtons' backgrounds with global stylesheet breaks its dimensions.:
@AlexNevskiy hmm... perhaps you need to change the sizePolicy?
Which policy will make it work?
Well i have most of my widgets on preferred since i dont understand the effects well enough:)
But if you add a pushbutton in designer it has horizontal: minimum.
7/10