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

How to elided text of all comboBox items?



  • Hi,

    Please look at this:

    https://stackoverflow.com/questions/41360618/qcombobox-elided-text-on-selected-item

    I would like the same, but not for QComboBox EditLine, but for QComboBox items. I tried change option.text in

    void myStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    

    but with no result.



  • @TomNow99
    If it's const QStyleOptionViewItem &option, how do you mean " I tried change option.text in" ? In the examples they are doing paintEvent(), not paint(). You may want to show some code.



  • @JonB my Bad :)

    void myStyledItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        QStyleOptionViewItem optionV4 = option;
        initStyleOption(&optionV4, index);
        optionV4.text="textAfterChange";
        QStyledItemDelegate::paint(painter,optionV4,index);
    }
    


  • Item delegates only works on item views, in your case, the popup view of the combo box.
    If you want to change the painting of combo box's current text, then it must be done in paintEvent() of the combo box.
    If you are talking about the items in the popup view, then I don't understand because they should be elided by default. (If you use your own item view, check QAbstractItemView::textElideMode.)


Log in to reply