Results 1 to 4 of 4

Thread: Small QPushButton possible? (less than 75 units)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default Small QPushButton possible? (less than 75 units)

    I am having a very difficult time trying to create a small qpushbutton. This is a simple issue that possibly ties into other issues I am encountering. I figured I would start with this simple problem and go from there.

    So, how do you make a small QPushButton in designer without explicitly setting it's maximumWidth? I want the layout (which the button is a member of) to shrink the button to a size that fits the button's text. The text might be only one or two characters long, so this is a SMALL button. I am only concerned with horizontal width (as opposed to vertical)

    Here is a simple setup in designer

    I have a qwidget as the main window.
    I have a horizontal layout set for the window
    I have qpushbutton in the layout (with button text 'X')
    I might optionally have a horizontal spacer (if it helps with the problem)

    For some reason, buttons do not get any smaller than 75 units (in width) unless explicitly told to do so (i.e through a geometry call or maximumWidth call). Does anyone know where this 75 unit rule is being made and how I might be able to get around it?

    You can see this issue very clearly in designer by placing a button in a window, and give it a simple text name like 'X', and then tell it to Adjust Size (ctrl+j). The button will never shrink down to its contents. It always stops at 75 pixels. I don't believe that this is a designer issue. I have tried writing the gui code from scratch and have the same problems.

    Can anyone enlighten me as to what is going on?

    Thanks

  2. #2
    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: Small QPushButton possible? (less than 75 units)

    Use QToolButton instead of QPushButton. Push buttons are meant to be wide.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    masterlaws (7th December 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    2
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: Small QPushButton possible? (less than 75 units)

    Well that sure is an easier route! Thanks!
    It doesn't quite explain to me the technical limitations of the qpushbutton, but I am comfortable using another widget instead. I had not used QToolButton before. Is there any reason not to use this button for most of my QPushButton needs? What's the drawback? They both inherit from QAbstractButton, so they must be quite similar.

    By the way, another hack, suggested in a different forum, was to calculate the button size needs by using the button text's fontMetrics.boundingRect(). This outputs the amount of space that a given string (in a given font) will need. I would then hard code the button's maximumWidth to this value.
    This allowed me to work around the problem, but again, doesn't explain what's going on under the hood with QPushButton

    Thanks for your help! Much appreciated

  5. #4
    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: Small QPushButton possible? (less than 75 units)

    There are no technical limitations. The significant differences between the two classes are that you can associate an action with a tool button, you can make it flat and that its minimum size is narrower than that of a push button because it is meant to be used on toolbars. Apart from that they are quite the same.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    masterlaws (7th December 2009)

Similar Threads

  1. Stylesheets & QPushButton menus
    By zuck in forum Qt Programming
    Replies: 5
    Last Post: 3rd November 2011, 15:40
  2. A very small push button
    By Gnurou in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2009, 03:04
  3. What is wrong with my code?
    By Dante in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2009, 07:56
  4. The application with connected units.
    By kuzulis in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 23:54
  5. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40

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.