Adding extra state behaviour for QPushButton
-
I have a set of checkable QPushButtons (to work like a QToolBar). Every one is connected to one action each. There are two general behaviour of these buttons: about half have one type, the other half the other. They are as follows:
- When the button is clicked, a (sometimes longer execution) action is triggered. Example: storing a file on disk.
- A different widget is shown.
Both types are highlighted (showed active) with a different icon and a icon border.
Type 1 (longer background task) has following desired behaviour:
- When a button is clicked, all buttons (including this clicked button and type 2) shall be disabled. However, to show which one is active, this clicked button will still act as highlighted (different icon and a icon border).
- When the background task has finished, the buttons that were enabled before shall be enabled again. Which ever button that was checked from Type 2 shall be checked again.
Type 2 (showing widget) has following desired behaviour:
- Only the current showing widget shall be highlighted (icon and icon border).
This was easily solved by grouping all Type 2 actions together and specify them as mutually exclusive.
The previous solution to this was:
- Part from the normal QIcon behaviour, specify that an icon which is disabled and checked shows the highlighted icon (as with active).
The problem lies with this:
All type 2 buttons are grouped as mutually exclusive, thus only one can be checked at a time. However it seems that one will ALWAYS be checked. This results in that when a Type 1 (longer background task) disables the UI, its icon will be shown as it were active, but it will also show a highlighted (active) icon for the first button of Type 2 even though it is disabled.Does someone know a nice solution to this that does not rely on the following:
- Not make the buttons of Type 2 mutually exclusive, but toggle them manually
- Override a ton of behaviour of various QPushButton paint and button actions.