I've solved subclassing QComboBox and reimplementing paintEvent():
{
QVariant itemData
= this
->itemData
( this
->currentIndex
(), Qt
::DisplayRole);
if(itemData.isValid()) {
p.
setPen(palette
().
color(QPalette::Text));
initStyleOption(&opt);
p.
drawComplexControl(QStyle::CC_ComboBox, opt
);
painter.save();
QRect rect
= this
->rect
();
rect.adjust(5,0,-5,0);
painter.drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, itemData.toString());
painter.restore();
} else {
}
}
void ComboBox::paintEvent(QPaintEvent *e)
{
QVariant itemData = this->itemData( this->currentIndex(), Qt::DisplayRole);
if(itemData.isValid()) {
QStylePainter p(this);
p.setPen(palette().color(QPalette::Text));
QStyleOptionComboBox opt;
initStyleOption(&opt);
p.drawComplexControl(QStyle::CC_ComboBox, opt);
QPainter painter(this);
painter.save();
QRect rect = this->rect();
rect.adjust(5,0,-5,0);
painter.drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, itemData.toString());
painter.restore();
} else {
QComboBox::paintEvent(e);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks