0

I need to customize the combo box which contains the text in the format " a rectangular color palette followed by a text description".

Iam using an a custom itemdelegate for a QComboBox . in the comboBox im checking the state of the Item and painting it according to my requirement like

if(option.state & QStyle::State_Selected)
        {
            painter->save();
            QRect r = option.rect;
            QRect textRect = r;
        textRect.setX(r.x() + 8);

        textRect.setWidth(r.width() - 10);

        textRect.setY(r.y() -3);
        textRect.setHeight(r.height() +2);
        painter->drawText(textRect.left(), textRect.top() , textRect.width(), textRect.height()  ,
        flags, currText, &r);
             painter->restore();
} else {
          ...
}

now i wanted to check if the role is a decorative role, if so then i have to add the pixmap and positioned it with item same like what i did for selected item inside paint function.

im not able to find how to paint a item with decorative role (image with text) .

How can I paint this text in the ItemDelegate ? this is my actual requirement enter image description here

Wagmare
  • 1,354
  • 1
  • 24
  • 58
Bharathi
  • 337
  • 1
  • 5
  • 17
  • What exact problem with painting do you have? It's unclear for me, what you are asking. You may get data with `index.data( Qt::DecorationRole );` – Dmitry Sazonov May 07 '14 at 10:29
  • This does not really answer your question, but can't you just use the available icon functionality for QComboBoxes? [`void QComboBox::addItem(const QIcon&, const QString&, const QVariant&)`](http://qt-project.org/doc/qt-4.8/qcombobox.html#addItem-2) – Bowdzone May 07 '14 at 12:48

0 Answers0