Hi,
What is the correct way to get a combobox to display images?
(The images are 120x90)
Do I need to create an ItemModel (derived from QAbstractItemModel) and then use QComboBox::setModel() ?
Or is there an easier way?
Thanks
Printable View
Hi,
What is the correct way to get a combobox to display images?
(The images are 120x90)
Do I need to create an ItemModel (derived from QAbstractItemModel) and then use QComboBox::setModel() ?
Or is there an easier way?
Thanks
you can try to create your own delegate.
so, you should get something like this
Code:
void PixmapDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { painter->drawPixmap(option.rect, pixmap); } { Q_UNUSED(option); return pixmap.size(); } ... cb->setItemDelegate(new PixmaDelegate(cb)); for (int i = 0; i < 10; ++i) { } vbl->addWidget(cb); ...
Thanks - I tried that but it does no give me the exact effect I need because when using it the current selection is not rendered as an image.
However, using:-
1) QAbstractItemModel and calling QComboBox::setIconSize to ensure the images are not scaled.
and 2) QItemDelegate for the drop list, I get the exact effect I need
reimplement QItemDelegate::drawFocus. you need write something like this
IMHO, you don't need any custom model for this task.Code:
void PixmapDelegate::drawFocus ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect ) const { Q_UNUSED(painter); Q_UNUSED(option); Q_UNUSED(rect); //nothig to do }