PDA

View Full Version : QPushbutton problem



amulya
29th August 2006, 08:35
hi all,

i m using a QPushButton in my program. It has a certain text.Now, this button is gonna be used as a toggle button. Hence, its text has to be changed depending on certain events.In my case, the second text is much bigger than the first text, and the text gets truncated cuz the size of the pushbutton remains the same.

Now, there is one way that i can just see the size of the second text and use setGeometry to give it the correct text. But the problem is , we r gonna use localisation and then this solution does not suit the situation

Is there any way by which the QPushbutton automatically resizes as the text of it changes. I would really appreciate a brisk reply. Thanx for ur time though

Cheers,
Amulya

munna
29th August 2006, 09:15
use fontMetrics() to get the FontMetrics of the button and then get the current text using text().

Using these two you can get the width of the text and then you can resize your button.

mcosta
29th August 2006, 10:29
Is there any way by which the QPushbutton automatically resizes as the text of it changes. I would really appreciate a brisk reply. Thanx for ur time though

Cheers,
Amulya

If the QPushButton is into a Layout its size is automatically updated.

roleroz
29th August 2006, 14:43
Even as if the button is inside a layout, you may find useful to use something as button->setFixedSize(button->sizeHint()) or the adjustSize() function

wysota
29th August 2006, 16:44
sizeHint() and minimumSizeHint() should take care of all the problems. If you need to do so, it is enough if you reimplement them. But if you use standard push button methods to set the text, it should be done automatically without any need to reimplement the above mentioned methods. It all depends how do you extend the button functionality.

Also, when putting buttons in a layout, make sure their size policy is set to Minimum, MinimumExpanding or Fixed.

amulya
30th August 2006, 09:11
hi guys,

thanx u all for such brisk replies. I used FontMetrics to solve my problem. I was using a customised button , may be cuz of which adding it to layout was not solving my problem. And it was not not automatically resizing. Anyways, i appreciate u spending time on my problem.

Cheers,
Amulya