Use the push button as a check button and use the grouping function
-
wrote on 9 Feb 2022, 08:47 last edited by
I know that I need to put setchakable(true) to use the pushbutton as a radio button.
Is there a way to automatically check each other's click status when creating multiple chakable buttons?
For example in C# you can group radio buttons so that only one is selected. Does qt provide the same functionality like this one?
-
Write it by yourself - a simple for loop isn't that hard.
-
Write it by yourself - a simple for loop isn't that hard.
wrote on 9 Feb 2022, 09:04 last edited byThere seems to be such a thing as a button group, how about applying it?
-
@IknowQT said in Use the push button as a check button and use the grouping function:
how about applying it?
What apply? Instantiate it, add buttons via addButton() and look if it works the way you want.
-
I know that I need to put setchakable(true) to use the pushbutton as a radio button.
Is there a way to automatically check each other's click status when creating multiple chakable buttons?
For example in C# you can group radio buttons so that only one is selected. Does qt provide the same functionality like this one?
wrote on 9 Feb 2022, 09:21 last edited by JonB 2 Sept 2022, 09:23@IknowQT said in Use the push button as a check button and use the grouping function:
For example in C# you can group radio buttons so that only one is selected. Does qt provide the same functionality like this one?
Yes QButtonGroup has that functionality. Note it says:
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.
So you still add your buttons onto whatever widgets like
QGroupBox
for visual layout, you also add the buttons onto the (non-visual)QButtonGroup
for the behaviour (like exclusivity) you want.
1/5