Solved Customization of push button
-
@J.Hilk
Thanks.
Yes, I'm sure this stylesheet applied. because I leave other button un-setting the stylesheet as a comparison, and it's obviously different: -
-
@David406 said in Customization of push button:
@J.Hilk
Thanks.
Yes, I'm sure this stylesheet applied. because I leave other button un-setting the stylesheet as a comparison, and it's obviously different:Hi again @David406
i am not sure that
setFlat(true)
is really what do you want,http://doc.qt.io/qt-5/qpushbutton.html#flat-prop
The doc actually says:
If this property is set, most styles will not paint the button background unless the button is being pressed.
And i think that this is your problem,
So i suggest you to delete the line
pushbutton->setFlat(true)
And setStylesheet of your PushButton as follow
QPushButton { border-style: outset; background-color: red ;/** for example **/ }
Keep me informed if this is what you want or no?
Best regards !
-
@mostefa
Thanks again.
Yes, this helped. But there are separators between the buttons which I don't want, see below:this is also the reason I used setflat(true). Any suggestion to eliminate those separators?
-
QPushButton{border: none;}
-
@David406 said in Customization of push button:
this is also the reason I used setflat(true)
Any suggestion to eliminate those separators?
How are you adding your buttons?
With yourPushButton->move(x + width - 8 * 32, y + height);
why -8*32 ,cause of spacing is maybe here, why just -8 * 32 ? -
@J.Hilk said in Customization of push button:
QPushButton{border: none;}
AFAIK border: none; will not change anything
-
@mostefa
Yes, border: none; is the default setting.
And I want to be able to move those buttons around, so I did not use layout to add these buttons. -
Just checked it, it does exactly what the OP want to, it removes the border/bulge of the default QPushButton
-
@J.Hilk
Yes, I checked it too. This really helped.
border-style:none; is default, not border:none;
Thank you all !!! -
Hi all, I have one more question. How can I let the buttons pushed down when mouse hovers on it, like below:
The arrow button is pushed down when my mouse hovers on it.
Could you please give some hints on what method to use? There's no hover or enter event for a button.Aside: When border is set to none, there would never appear a border even when I pused on it, which is not what I meant to do. Confused!
-
QStyleSheet is also here your friend. For example:
QPushButton:hover{background-color:red;}
-
@J.Hilk
Oh, yes! Please forgive me, I'm quite new about the usage of stylesheet! So I need to set different stylesheet for normal, hover and pushed status. -
that would be correct:
a small example:
ui->myButton->setStyleSheet( //Default Button "QPushButton{border:none; color: black; background-color:transparent;}" //When mose over "QPushButton:hover{border: 1px solid grey; color: red; background-color:white;}" //When checked "QPushButton:checked{border: 1px solid black; color: white; background-color:red;}" );