[Interest] How to produce a cluster of radio buttons?

Shriramana Sharma samjnaa at gmail.com
Fri Aug 31 08:53:20 CEST 2012


On Fri, Aug 31, 2012 at 11:55 AM, Tony Rietwyk <tony at rightsoft.com.au> wrote:
> If you set the enclosing Widget size policy to Fixed, then it should use the
> minimum required for its layout anyway.   You can also play with the
> layout's size constraint property.

Hi thanks to all who replied.

I might consider using a QToolButton if I want to put in an icon. And
by setting the widget's size policy to fixed I found that it actually
uses more width than is needed (for whatever reason) thereby not
making the radios uniformly spaced horizontally vs vertically.

I ended up writing:

refPtWidget = QWidget ( window )
refPtGrid = QGridLayout ( refPtWidget )
refPtGrid . setHorizontalSpacing ( 0 )
refPtGrid . setContentsMargins ( 0, 0, 0, 0 )
refPtArray = []
for i in range ( 3 ) :
	rowArray = []
	for j in range ( 3 ) :
		button = QRadioButton ()
		rowArray += [ button ]
		refPtGrid . addWidget ( button, i, j )
	refPtArray += [ rowArray ]
radioHeight = refPtArray [ 0 ] [ 0 ] . sizeHint () . height ()
refPtWidget . setFixedSize ( radioHeight * 3, radioHeight * 3 )

I suppose I can achieve lesser spacing between the painted than this
by hardcoding some negative spacing or something, but I didn't want to
(as it may cause clipping depending on the margin the sizeHint
provides around the drawn button) and I just respected the sizeHint of
the QRadioButtons.

Thanks again.

-- 
Shriramana Sharma



More information about the Interest mailing list