summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-05-20 13:25:27 +0200
committerOlivier Goffart <ogoffart@trolltech.com>2009-05-20 13:47:58 +0200
commitfdefbb820f1ebf9fbde0f683ea6d05923e8c04e4 (patch)
tree5dac0f832a8ce60f1724d9978b604df64fd3e5f3 /src/gui/widgets
parent25f86fbab2e7d23832b0bb8ae8530289258e2aa5 (diff)
QComboBox: style change event should not resets custom item delegates
Regression from 4.4 introduced while fixing task 167106 Autotest: tst_QComboBox::task253944_itemDelegateIsReset() Task-number: 253944 Reviewed-by: jbache
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qcombobox.cpp22
-rw-r--r--src/gui/widgets/qcombobox_p.h6
2 files changed, 19 insertions, 9 deletions
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp
index 09a51fe39f..a5a98d48b9 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
diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h
index c39a23140c..a55b439e8d 100644
--- a/src/gui/widgets/qcombobox_p.h
+++ b/src/gui/widgets/qcombobox_p.h
@@ -256,7 +256,7 @@ private:
};
class QComboMenuDelegate : public QAbstractItemDelegate
-{
+{ Q_OBJECT
public:
QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {}
@@ -285,7 +285,7 @@ private:
// Vista does not use the new theme for combo boxes and there might
// be other side effects from using the new class
class QComboBoxDelegate : public QItemDelegate
-{
+{ Q_OBJECT
public:
QComboBoxDelegate(QObject *parent, QComboBox *cmb) : QItemDelegate(parent), mCombo(cmb) {}
@@ -367,7 +367,7 @@ public:
int itemRole() const;
void updateLayoutDirection();
void setCurrentIndex(const QModelIndex &index);
- void updateDelegate();
+ void updateDelegate(bool force = false);
void keyboardSearchString(const QString &text);
void modelChanged();