c++qt

Qt: Disable a Push Button without turning it gray


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:

  1. Is there a way to disable the gray out effect when I use button.setEnabled(false)?

  2. 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.


Solution

  • 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...

    From doc:

    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.