I'm reimplementing paintEvent
for QComboBox and paint
for delegate, based on QStyledItemDelegate
. The problem is with my code, the text is elided, but the size of the background is not.
What can be the reason, which object is responsible for this background?
delegate's paint
reimplemented method:
void myDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem opt = option;
initStyleOption(&opt, index);
opt.rect.setWidth(_parentComboRect->width());// gets parent's size
opt.textElideMode = Qt::ElideRight;
const QWidget *widget = opt.widget;
QStyle *style = widget ? widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
}
Any suggestions?
I found the solution!
void MyCombo::showPopup() // an overridden function
{
view()->window()->setFixedWidth(100);// ->window() makes that field!
QComboBox::showPopup();
}