Results 1 to 7 of 7

Thread: Calculating button width

  1. #1
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Calculating button width

    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 ?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Calculating button width

    did you try calculation in showevent()?

  3. The following user says thank you to nish for this useful post:

    Skizmo (17th February 2011)

  4. #3
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calculating button width

    Good idea... didn't think of that, but after testing, nope. The width is still the same

  5. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Calculating button width

    Maybe this will fix your Problem? [WIKI]Expanding_dialog[/WIKI]

  6. #5
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calculating button width

    Quote Originally Posted by nightghost View Post
    Maybe this will fix your Problem? [WIKI]Expanding_dialog[/WIKI]
    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 ).

  7. #6
    Join Date
    Jun 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calculating button width

    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).

  8. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Calculating button width

    glad it worked for you

Similar Threads

  1. Calculating best bounding box for text
    By xtal256 in forum Qt Programming
    Replies: 2
    Last Post: 1st October 2010, 08:38
  2. Replies: 1
    Last Post: 2nd August 2010, 06:40
  3. QToolBox width fixed to maximum content width
    By ghorwin in forum Qt Programming
    Replies: 0
    Last Post: 10th July 2009, 10:58
  4. How to set QTableView width to width of horizontal header?
    By martinb0820 in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 21:51
  5. calculating checksum in serialcommunication
    By jjbabu in forum Qt Programming
    Replies: 5
    Last Post: 12th October 2007, 13:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.