PDA

View Full Version : Calculating button width



Skizmo
17th February 2011, 10:32
Hi,

I want to create some buttons run-time, based on the program parameters. The problem I have is that the text on a button determines the width of a button. The more text there is on a button, the wider it becomes. In that case the dialog needs to be bigger too. Is there a way to pre-calculate the width of a button before actually showing it ? I tried creating the button on a window before showing it so I could get the width, but it seems that in that case the long text size isn't calculated and all buttons claim they have the same size, but as soon as I show the dialog, the long text on the button resizes the button and the pre-calculated width is wrong.

Any ideas ?

nish
17th February 2011, 10:54
did you try calculation in showevent()?

Skizmo
17th February 2011, 11:09
Good idea... didn't think of that, but after testing, nope. The width is still the same :mad:

nightghost
17th February 2011, 11:12
Maybe this will fix your Problem? Expanding_dialog

Skizmo
17th February 2011, 11:35
Maybe this will fix your Problem? Expanding_dialog

I initially started using the QLayout class when I started my project, but due to all the possibilities in my layout I stopped using it and I'm doing the calculations myself (which created my current problem ;) ).

Skizmo
17th February 2011, 14:09
Nish, I take back my words. I was checking you suggestion with the debugger, and the debugger was fooling me. Don't know what's going on here, but if I use the debugger to check the button width, I get the standard button size (and I don't get to see the full text on the button) and if I trace the data and run it without the debugger I get the correct size. So, checking the width in the showEvent actually works (but is ofcourse a horrible solution but I guess I have no other choice).

nish
17th February 2011, 15:12
glad it worked for you :)