Customization of push button
-
Hi,
the better way to solve this issue:
First, using AQLayout
that way you dont have to move your buttons individually and they adjust to changes in size automaticaly.Second, set the Picture via a StyleSheet like @mostefa suggested:
setStyleSheet("QPushButton{border-image:url(pathToImg/img.png)}");
You have the space between the buttons because, the Icon is not the whole PushButton
To have the buttons, when inside a Layout, right next to each other, remember to set the spacing to 0.
-
@David406
maybe QToolButton is another choice?wrote on 27 Mar 2017, 12:37 last edited by@Flotisable
Do you mean QToolBar? This seems to be a good choice. -
@J.Hilk
Thanks a lot. Your suggestions are very helpful. But I also would like to move the layout widget to a give position. However, QHBoxLayout widget do not have this method. Do you have any suggestions?@David406 generally, I would suggest to place your whole UI into an interlocking construct of
QLayouts
.But if you dont want to do that,
You can use a QFrame or QWidet as a parent for the QLayout and move that around. -
@Flotisable
Do you mean QToolBar? This seems to be a good choice.wrote on 27 Mar 2017, 15:14 last edited by@David406
no,QToolButton
is a special button that is usually used inQToolBar
you can read the document of QToolButton and QToolBar
-
wrote on 27 Mar 2017, 15:45 last edited by
@David406
set it for all your button,
button->setFlat(true);
it solves your problem. -
wrote on 28 Mar 2017, 11:05 last edited by David406
Hi all, thanks for all of your help! I tried to set my buttons flat with
button->setFlat(true);
and it looks good. But there is still a problem remained, that is, I can't set
the background color the these button. I was using stylesheetdrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
See below:
The background color only come into effect when I click on the button:
Any suggestions?
-
Hi all, thanks for all of your help! I tried to set my buttons flat with
button->setFlat(true);
and it looks good. But there is still a problem remained, that is, I can't set
the background color the these button. I was using stylesheetdrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
See below:
The background color only come into effect when I click on the button:
Any suggestions?
are you sure the stylesheet is applied at all? And is this the only place where you set a stylesheet;
theres a t least a
;
missing, what usually results in a stylesheet parsing error.drawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255);}");
-
Hi all, thanks for all of your help! I tried to set my buttons flat with
button->setFlat(true);
and it looks good. But there is still a problem remained, that is, I can't set
the background color the these button. I was using stylesheetdrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
See below:
The background color only come into effect when I click on the button:
Any suggestions?
wrote on 28 Mar 2017, 11:10 last edited by mostefa@David406 said in Customization of push button:
Hi all, thanks for all of your help! I tried to set my buttons flat with
button->setFlat(true);
and it looks good. But there is still a problem remained, that is, I can't set
the background color the these button. I was using stylesheetdrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
See below:
The background color only come into effect when I click on the button:
Any suggestions?
Is your QPushButton checkable??
If yes you need to add stylesheet when button is checked
I think that this should be something like this:
QPushButton:checked{background-color: white;};
-
@David406 said in Customization of push button:
Hi all, thanks for all of your help! I tried to set my buttons flat with
button->setFlat(true);
and it looks good. But there is still a problem remained, that is, I can't set
the background color the these button. I was using stylesheetdrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
See below:
The background color only come into effect when I click on the button:
Any suggestions?
Is your QPushButton checkable??
If yes you need to add stylesheet when button is checked
I think that this should be something like this:
QPushButton:checked{background-color: white;};
wrote on 28 Mar 2017, 11:31 last edited by David406@mostefa
Thanks.
Yes, my button is checkable.
I think you mis-understand my intention. I want my buttons to be set with background color of my choice without even pressing it. However, this codedrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
only works when I push the button (second picture). When the buttons are un-pushed, the background color set in the setStyleSheet does not help in any means (first picture).
-
@mostefa
Thanks.
Yes, my button is checkable.
I think you mis-understand my intention. I want my buttons to be set with background color of my choice without even pressing it. However, this codedrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
only works when I push the button (second picture). When the buttons are un-pushed, the background color set in the setStyleSheet does not help in any means (first picture).
wrote on 28 Mar 2017, 11:33 last edited by@David406 said in Customization of push button:
@mostefa
Thanks.
Yes, my button is checkable.
I think you mis-understand my intention. I want my buttons to be set with background color of my choice without even pressing it. However, this codedrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
only works when I push the button (second picture). When the buttons are un-pushed, the background color set in the setStyleSheet does not help in any means.
Ok
Then what about
unchecked
property?QPushButton:unchecked{background-color: white;};
-
are you sure the stylesheet is applied at all? And is this the only place where you set a stylesheet;
theres a t least a
;
missing, what usually results in a stylesheet parsing error.drawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255);}");
-
@David406 said in Customization of push button:
@mostefa
Thanks.
Yes, my button is checkable.
I think you mis-understand my intention. I want my buttons to be set with background color of my choice without even pressing it. However, this codedrawArrowBtn->setStyleSheet("QPushButton{background-color:rgb(255, 255, 255)}");
only works when I push the button (second picture). When the buttons are un-pushed, the background color set in the setStyleSheet does not help in any means.
Ok
Then what about
unchecked
property?QPushButton:unchecked{background-color: white;};
-
@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:wrote on 28 Mar 2017, 11:45 last edited by mostefa@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 !
-
@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;}
-
@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?
wrote on 28 Mar 2017, 12:16 last edited by mostefa@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 ? -
wrote on 28 Mar 2017, 12:20 last edited by
@J.Hilk said in Customization of push button:
QPushButton{border: none;}
AFAIK border: none; will not change anything
-
@J.Hilk said in Customization of push button:
QPushButton{border: none;}
AFAIK border: none; will not change anything
-
@J.Hilk said in Customization of push button:
QPushButton{border: none;}
AFAIK border: none; will not change anything
Just checked it, it does exactly what the OP want to, it removes the border/bulge of the default QPushButton
-
Just checked it, it does exactly what the OP want to, it removes the border/bulge of the default QPushButton
14/28