[PyQt] Determine size of a button

Joe M j.moudrik at gmail.com
Fri Oct 14 10:39:49 BST 2011


Hello,

I am writing an application (a songbook). In one of the parts, I have a
custom widget, that displays some information in lines. One line looks like
this 

QLabel (with fixed size) QPushButton QPushButton ....
an instance looks like
Genre: Rock Folk Metal
(genre = label, Rock = first button, ..)
I'd like to find appropriate songs when user clicks e.g. Rock)

This panel is embedded in a widget whose size determined by user (by
splitter). Because sometimes, there are a lot of genres for a song, the
panel gets too big and it results in resize that changes the user-defined
size. I've come up with a solution: if there are more than 3 buttons
(genres) I merge the rest into a button with pop-up menu. This looks nice,
but I'd like to base the merging on size of the genre buttons rather that on
their number. (because sometimes the number is large, but the genres
themself are short)

I've come up with another solution, which I do not like at all: Create the
buttons, catch the parent's resize event (if any) and merge the buttons
afterwards.

The question is: is there a way in which I can tell how big the buttons will
be without having to create them in the first place? Or any other hints?

Thanks!
-- 
View this message in context: http://old.nabble.com/Determine-size-of-a-button-tp32648218p32648218.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list