diff options
Diffstat (limited to 'src/gui/widgets/qcombobox.cpp')
-rw-r--r-- | src/gui/widgets/qcombobox.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 09a51fe..a5a98d4 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -947,7 +947,7 @@ QComboBoxPrivateContainer* QComboBoxPrivate::viewContainer() container = new QComboBoxPrivateContainer(new QComboBoxListView(q), q); container->itemView()->setModel(model); container->itemView()->setTextElideMode(Qt::ElideMiddle); - updateDelegate(); + updateDelegate(true); updateLayoutDirection(); QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), q, SLOT(_q_itemSelected(QModelIndex))); @@ -1567,15 +1567,25 @@ bool QComboBox::isEditable() const return d->lineEdit != 0; } -void QComboBoxPrivate::updateDelegate() +/*! \internal + update the default delegate + depending on the style's SH_ComboBox_Popup hint, we use a different default delegate. + + but we do not change the delegate is the combobox use a custom delegate, + unless \a force is set to true. + */ +void QComboBoxPrivate::updateDelegate(bool force) { Q_Q(QComboBox); QStyleOptionComboBox opt; q->initStyleOption(&opt); - if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) - q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); - else - q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); + if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { + if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate())) + q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); + } else { + if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate())) + q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); + } } QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const |