[PyQt] How to use QButtonGroup?

David Boddie david at boddie.org.uk
Sun Nov 25 22:58:52 GMT 2007


On Sun Nov 25 14:05:39 GMT 2007, Sibylle Koczian wrote:

> I'm reading the documentation about QButtonGroup and QGroupBox and I don't 
> quite understand the relationship between them. 

I think the relationship between them in Qt 3 is a different to that in Qt 4,
so that might also be a cause of confusion for some people.

> I can create QRadioButtons and put them into a QGroupBox. That makes them 
> visible and mutually exclusive. And, of course, I should put a layout
> between the box and the buttons. Right?

Correct.

> If I put those same buttons into a QButtonGroup, then I can map them to 
> integers, and I can connect the buttonClicked(int) signal of the group to a 
> method or function that can use the id of the button. Still right?

Correct again.

> But there seems to be no connection between the QGroupBox and the 
> QButtonGroup. I have to put each of my radio buttons into the box _and_ into 
> the buttongroup. Right, or did I overlook something?

Yes, the QButtonGroup object just acts as a messenger for the buttons. You
still need to put them inside a widget, and a QGroupBox widget is usually the
sort of widget you would use.

David



More information about the PyQt mailing list