PDA

View Full Version : Qpushbutton not clickable but not greyed



gab74
13th December 2011, 18:00
Hi,
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...

Thanks

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

amleto
14th December 2011, 00:12
you could do it with an event filter as well.

aamer4yu
14th December 2011, 14: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.

gab74
15th December 2011, 10: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...

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

Spitfire
15th December 2011, 10: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.

gab74
15th December 2011, 12: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...

Spitfire
15th December 2011, 13: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 );
l->setStyleSheet(
"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 );"
"}"
);