Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to elided text of all comboBox items?

How to elided text of all comboBox items?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 942 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • T TomNow99

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        @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);
        }
        
        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

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

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved