Reputation: 574
I need to make a checkable Push Button in Qt 4.8 that when is checked it becomes disabled.
The problem that I have is that the button turns gray and I need to keep it with the same color always. I have two questions for two possibles paths to follow:
Is there a way to disable the gray out effect when I use button.setEnabled(false)?
Is there a way to hook the click event so I can "simulate" the disabled property?
[Edit] To give a little context, I have two push buttons that should toggle each other and that's why I need to prevent clicking on a pressed button.
Upvotes: 1
Views: 4237
Reputation: 1
Using a stylesheet you can specify the colors you want when the button is in a disabled state, e.g., myBtn.setStyleSheet("QPushButton:disabled{background-color: mycolor;})
.
Upvotes: 0
Reputation: 1
For disabling toolbutton and put icon of your choice instead of turning into grey
icon.addPixmap(qpm,QIcon::Disabled,QIcon::On)
this line will show iconWhen enabling Toolbutton just change
3. icon.addPixmap(qpm,QIcon::Normal,QIcon::On)
Upvotes: 0
Reputation: 2350
To give a little context, I have two push buttons that should toggle each other and that's why I need to prevent clicking on a pressed button.
You should use QButtonGroup instead.
The only way that the button should be unchecked is when the user checks the other button...
In an exclusive group, the user cannot uncheck the currently checked button by clicking on it; instead, another button in the group must be clicked to set the new checked button for that group.
Upvotes: 0
Reputation: 1277
Try button.blockSignals(true). You could also overwrite the look of the button when its disabled with a Qt style sheet.
Upvotes: 3