Results 1 to 2 of 2

Thread: QComboBox text alignment via CSS, and QComboBox ListItem Height

  1. #1
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Exclamation QComboBox text alignment via CSS, and QComboBox ListItem Height

    Hi All,

    I've two little trouble with my QComboBox that make me crazy.
    The first one, is that i would like to right align the selected item text via CSS inside QComboBox.(like the behavior of the QSpinBox).
    qcombo.png
    I tried, more or less, everything inside my css but seems impossible to do.
    This is my current CSS:
    Qt Code:
    1. border: 1px solid darkgray;
    2. border-radius: 0px;
    3. padding-right: 20px;
    4. min-width: 6em;
    5. color: black;
    6. }
    7.  
    8. QComboBox:!editable, QComboBox::drop-down:editable {
    9. selection-color: rgb(0, 150, 200);
    10. background: white;
    11. }
    12.  
    13. QComboBox::drop-down {
    14. subcontrol-origin: padding;
    15. subcontrol-position: top right;
    16. width: 15px;
    17. height: 30px;
    18. border-width: 0px;
    19. border-left-width: 1px;
    20. border-left-color: darkgray;
    21. border-left-style: solid; /* just a single line */
    22. border-top-right-radius: 0px; /* same radius as the QComboBox */
    23. border-bottom-right-radius: 0px;
    24. }
    25.  
    26. QComboBox::down-arrow {
    27. image: url(:/images/icons/caret-down_262626_16.png);
    28. }
    29.  
    30. QComboBox::drop-down:on {
    31. top: 0px;
    32. left: 0px;
    33. background: rgb(0, 150, 200);
    34. }
    35.  
    36. /* background-color: rgb(0, 150, 200);
    37.   border-radius: 0px;*/
    38. selection-background-color:white ;
    39. selection-color:rgb(0,150,200) ;
    40. }
    To copy to clipboard, switch view to plain text mode 

    The second question is regarding the items in the QComboBox list. Is possible, still through CSS, to set height of those items?
    More in detail, i would like to increase the space between the items. How you can see from the picture below, the height is the same of each item.
    height.png

    Thanks a lot for any suggestion.

  2. #2
    Join Date
    Jan 2015
    Posts
    15
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QComboBox text alignment via CSS, and QComboBox ListItem Height

    Ok, i found an workaround(unfortunately seems there is no way to do this by css)... and it's not so bad.

    I created a custom class that inherited from QComboBox.
    Then in the constructor i set the QComboBox editable and put the related QLineEdit disabled.
    Setting the QLineEdit property readOnly = true and the correct right alignment(Qt::AlignRight) did the trick.

    Below is attached the code. (For someone, like me, that became crazy for this stupid behavior).
    Qt Code:
    1. #include "customcombobox.h"
    2. #include <QLineEdit>
    3.  
    4. CustomComboBox::CustomComboBox(QWidget *parent) : QComboBox(parent)
    5. {
    6. this->setEditable(true);
    7. this->lineEdit()->setDisabled(true);
    8. this->lineEdit()->setReadOnly(true);
    9. this->lineEdit()->setAlignment(Qt::AlignRight);
    10. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Vertical alignment for QComboBox
    By Julieng031 in forum Newbie
    Replies: 3
    Last Post: 17th April 2014, 14:10
  2. Same height for QComboBox and QPushButton
    By cevou in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2012, 08:56
  3. QComboBox text alignment
    By mentalmushroom in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2012, 22:33
  4. Alignment in QComboBox
    By Naami in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2010, 15:53
  5. QComboBox dropdown Height
    By minsoub in forum Qt Programming
    Replies: 2
    Last Post: 23rd February 2010, 09:02

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.