Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Setting QComboBox stylesheet reduces hight of dropdown [SOLVED]



  • Hi all,

    I want my combobox to be blue. That is achieved by setting the stylesheet:
    @combo->setStyleSheet("color: blue");@

    There is only one downside:
    Setting the above styling reduces the amount of items displayed when the combobox is clicked on the subitem list is displayed.
    https://skydrive.live.com/redir?resid=47024E7C0E1A51D7!6780&v=3

    What can I do to set the textcolor and have all subitems of the combobox displayed when I click on the combobox.

    kind regards, reinhart


  • Moderators

    you can try this:
    @
    QAbstractItemView * view = combo->view();
    QPalette p = view->palette();
    p.setColor(QPalette::Text,Qt::blue);
    view->setPalette(p);
    @
    Not tested though.



  • Thanks a lot - works nicely!



  • qss for combo should not affect the number of visible items

    where/when do you apply the style sheet?

    just in case you could control the number of max visible items, after the style sheet setting, with:

    @ui->comboBox->setMaxVisibleItems(5);@

    or

    @ui->comboBox->setStyleSheet("qproperty-maxVisibleItems:3");@



  • Hi,
    the combobox is part of a QTableWidget. I think setting the stylesheet overwrites some default stylings (at least that is my explaination I don't know if that's true).
    Thanks for the hint with maxvisible item, though!
    regards, reinhart


Log in to reply