PDA

View Full Version : QPushbutton, background-color but flat ?



gab74
13th December 2011, 18:02
I've a QPushBUtton

i want to change the button color so i use a simple stylesheet

setStyleSheet("QPushButton { background-color: red; color: black;}");

The button is now red and text black, but it is became FLAT !!! So no, border and simple 3d effect like the standard button..

Why this ?

amleto
13th December 2011, 23:13
why? because that is what you told it to do. :confused:

aamer4yu
14th December 2011, 13:48
For QPushButton, changing the background , you will need to change other properties as well.
Usually QPushButton paints according to the system theme. You will need to use some image with 3D effect for the button to look better.

Also there are ways to change colors of button using custom button.

gab74
15th December 2011, 08:56
My problem is that i have a simple panel with a button grey, with default qt style,
but if i simply change the background to make the button red, the button becomes red but it not seems to be a button because it becomes flat, it seems a text box !!

Spitfire
15th December 2011, 10:15
QPushButton* pb = new QPushButton("Test", this);
pb->setStyleSheet(
"QPushButton {"
"margin: 1px;"
"border-color: #0c457e;"
"border-style: outset;"
"border-radius: 3px;"
"border-width: 1px;"
"color: black;"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2198c0, stop: 1 #0d5ca6);"
"}"
"QPushButton:pressed {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #0d5ca6, stop: 1 #2198c0);"
"}"
);
Change what you want to what you want but general idea is that you have to style the button yourself from scratch.