View Full Version : Qpushbutton not clickable but not greyed

13th December 2011, 17:00
i need a QPushbutton not clickable but not greyed as disabled...

Is there a way to reach this result ?

The button text must remain not greyed.
The background not greyed...


13th December 2011, 18:50
Subclass QPushButton and reimplement mousePressEvent.

13th December 2011, 23:12
you could do it with an event filter as well.

14th December 2011, 13:37
i need a QPushbutton not clickable but not greyed as disabled...
Sounds more like a label right ? You could use a label with pushbutton image as background.
Or you can go as suggested above.. subclass QPushButton and reimplement mousepressevent and ignore it.

15th December 2011, 09:01
Thanks to all...at the moment i've no code,
my apps need 2 buttons, when it starts i want only one disabled, but i need that the style of disabled button is the same of the enabled button, so no greyed....as setEnabled(false) property do.
I need only that one button is unclickable...

15th December 2011, 09:32
use Stylesheets and set a style to QPushButton without explicitly specifying QPushButton[enabled=false]

15th December 2011, 09:47
I would question your design.

Why you need a button that looks like enabled but it isn't?

One thing you'll get for sure is user confusion.

15th December 2011, 11:29
Yes you are right !! But this button will work like a led GREEN/RED. And the only widget to make a like led is a QPushButton...!!!
A QLineEdit is flat so i think a QPUSHButton is the best solution...

15th December 2011, 12:21
I still think you need to re-think your design.
You need a button which is not a button, but looks like a button but it fact is a label...

Read what you're saying - the idea of a button is that it can be interacted with. You're looking for something that will not be interacted with.

What about QLabel? That's exacly what it is for.

You can style the label as you want, even to look like a PushButton (I still fail to see a reason for that).

QLabel* l = new QLabel("Test", this);
l->setAlignment( Qt::AlignCenter );
"QLabel {"
"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 #EBEBEB, stop: 1 #CCCCCC );"