Results 1 to 6 of 6

Thread: QPushbutton problem

  1. #1
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Post QPushbutton problem

    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

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushbutton problem

    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.
    Last edited by munna; 29th August 2006 at 08:16. Reason: spelling mistake

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPushbutton problem

    Quote Originally Posted by amulya
    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.
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    Aug 2006
    Posts
    15
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPushbutton problem

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPushbutton problem

    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.

  6. #6
    Join Date
    Mar 2006
    Posts
    19
    Thanks
    1

    Default Re: QPushbutton problem

    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

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.