PDA

View Full Version : How to make QPushbuttons with same parent non-exclusive



davethomaspilot
7th December 2012, 22:32
I've been struggling with how to get a collection of toggling QPushbuttons (not checkboxes) that aren't exclusive. Each button should be checkable regardless of the state of the other buttons.

I've set "checkable" and tried both autoexclusive on and off.

I think I need them in some kind of container, since I want to use the group in several places in the GUI. They are in a vertical layout now.

I read about QButtonGroup, but I don't see one of those in Qt Designer that I could try out.

Is QButtonGroup what's needed to get non-exclusive QPushButtons? Can I get one from Qt Designer, or do I need to just add it in the code myself?

Thanks,

Dave Thomas

wysota
7th December 2012, 22:48
Where did you place those buttons? I mean what is their parent widget?

ChrisW67
9th December 2012, 07:01
I just dropped three default QPushButtons on a generic QWidget parent in Designer, marked them all checkable, and the default behaviour is that they operate independently as you are asking for. The same is true for a default QGroupBox container. What container are you using?

You can access QButtonGroup in Designer but it is not immediately obvious. Select the push buttons you want in the group, right click for the context menu and select "Assign to button group...". The default behaviour of the group is to make the buttons exclusive, precisely the opposite of the default behaviour and your required behaviour.

davethomaspilot
9th December 2012, 13:45
Their parent was a vertical layout in the central widget of a mainWindow.

I figured out how to add them to a QButtonGroup and when I unchecked that group's exclusive property, I got what I want.

Thanks,

Dave Thomas

ChrisW67
9th December 2012, 21:33
The layout does not own the widgets is controls layout for; they are owned by a QWidget. If you do not parent the widgets explicitly then their parent is set by the layout when you apply it to a container.