Results 1 to 6 of 6

Thread: Same height for QComboBox and QPushButton

  1. #1
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Same height for QComboBox and QPushButton

    Hi,

    I want a QComboBox to automatically get the height from a QPushButton which has default height.
    When I try to read the buttons height with button->height() it returns something like 380, however it displays with a height of like 20.

    How can I get the real height without setting the height of the button?

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Same height for QComboBox and QPushButton

    Could you paste a small compilable example for us to test? A bit of code would help us to see the problem.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Same height for QComboBox and QPushButton

    Ok, hope that helps you:

    Qt Code:
    1. QPushButton *select = new QPushButton("auswählen");
    2. cmb = new QComboBox;
    3. cmb->setFixedHeight(select->geometry().height()); //select->geometry().height() returns 380 instead of the actual height
    To copy to clipboard, switch view to plain text mode 

    The PushButton's height is somehow defined by the OS and Layout.
    In Windows Vista for example the standard height of the QComboBox is not equal to the standard height of a QPushButton. That's why I want to do all that stuff.
    Last edited by cevou; 28th October 2008 at 21:22.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Same height for QComboBox and QPushButton

    The widget must first be shown to have a valid size (height/width). Try to read the sizeHint instead though it may not be the actual size the widget gets once it is displayed. It will however come pretty close though to the size the widget will have once it is first shown.

  5. #5
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Same height for QComboBox and QPushButton

    Thanks! That worked!

  6. #6
    Join Date
    Jan 2012
    Location
    St. Petersburg, Russia
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Same height for QComboBox and QPushButton

    You can use stylesheet as a hack when you are close to pulling you hairs off:

    Qt Code:
    1. comboBox->setStyleSheet("QComboBox { padding-top: 2px; padding-bottom: 1px; }");
    To copy to clipboard, switch view to plain text mode 

    It will correct ComboBox size.
    You supply your own values (with QString::arg(), for instance).

Similar Threads

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