3

I want to set appearance of QComboBox's items like this:

enter image description here

Modern environments (like windows, mac, etc) don't contain similar styles, so I suppose repainting is the best way to solve this problem. Qt doc says that reimplementing paint method of QStyledItemDelegate class can help, but I cannot understand, how can I retrieve specific information from arguments of such method (example from qt 5.5):

void QStyledItemDelegate::paint(QPainter *painter,const QStyleOptionViewItem&option, const QModelIndex &index) const
{
   //how to get specific info from index object?
}

Maybe is there another best and elegant way of solving this problem?

Alex Aparin
  • 4,393
  • 5
  • 25
  • 51
  • It seems like I found potential way to solve this problem, one of the qt's examples has similar description - http://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html – Alex Aparin Mar 25 '16 at 12:43
  • 1
    Yep, you found one example. Another one [here](http://stackoverflow.com/a/5346900/5653461). For a best visual rendering, you may want to use some CSS... – IAmInPLS Mar 25 '16 at 12:46
  • 1
    `index.data()` is the way to retrieve the information you're looking for. Read more info about [Qt MVC programming](https://doc.qt.io/qt-5/model-view-programming.html). – peppe Mar 25 '16 at 18:22

0 Answers0