Results 1 to 7 of 7

Thread: [CSS/QCombobox] setting min-height for drop down list

  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [CSS/QCombobox] setting min-height for drop down list

    Hi,

    I want to set the minimal height of an item of the drop down list of a QComboBox via a cascade style sheet. There seems to be no way to do this, but still I want to check if someone has any clue how to do this.

    You can set the min-height for the combobox itself, but not for the dropdownlist.

    to be clear: I don't want to increase the size of the font, just the space between the different items (for touch-screen purposes...)

  2. #2
    Join Date
    May 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    I have exactly the same problem. I tried a lot of different styles to apply, but none of them worked. In my opinion, the following CSS should work, but it doesn't:
    Qt Code:
    1. {
    2. padding-top: 10px;
    3. padding-bottom: 10px;
    4. }
    To copy to clipboard, switch view to plain text mode 
    I tried also the tip from another thread (http://www.qtcentre.org/forum/f-qt-p...box-12025.html) to add the QApplication::globalStrut. This works for all Widgets, except AbstractItemView of the QComboBox.

    I'm at the moment with Qt 4.3.2, and will try it today with Qt 4.4.

    One solution would be to implement a custom model. But it would be so nice if I don't have to implement a custom model.

  3. #3
    Join Date
    Jul 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    Solution is (at least for Qt 4.6.0):

    Qt Code:
    1. setStyleSheet("QComboBox { min-height: 40px; min-width: 60px; }"
    2. "QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
    3. QComboBox *combo = new QComboBox(this);
    4. combo->setView(new QListView());
    To copy to clipboard, switch view to plain text mode 
    if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.

  4. #4
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    Thanks very much for this solution.
    Works too with 4.7.2, seems to still be the same bug.

  5. #5
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    It works!But I wonder if every QComboBox uses "combo->setView(new QListView());",Could it cause memory leak?

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    Quote Originally Posted by æž—å©· View Post
    It works!But I wonder if every QComboBox uses "combo->setView(new QListView());",Could it cause memory leak?
    No, it couldn't.
    The doc says:
    Sets the view to be used in the combobox popup to the given itemView. The combobox takes ownership of the view.
    Read about QComboBox::setView carefully.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: [CSS/QCombobox] setting min-height for drop down list

    Quote Originally Posted by MarkRus View Post
    Solution is (at least for Qt 4.6.0):

    Qt Code:
    1. setStyleSheet("QComboBox { min-height: 40px; min-width: 60px; }"
    2. "QComboBox QAbstractItemView::item { min-height: 40px; min-width: 60px; }");
    3. QComboBox *combo = new QComboBox(this);
    4. combo->setView(new QListView());
    To copy to clipboard, switch view to plain text mode 
    if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.
    if you omit the last line (setView call), the style sheet wont be applied to the default combobox item view.
    It should be higtligeted!.

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.