Correctly update QComboBox appearance on editable change
The updateDelegate() function checks isEditable() which in turn checks if d->lineEdit != 0, so we need to make the call after the lineEdit has actually been set/unset, otherwise the change to the delegate will not come until the next time you update the delegate. [ChangeLog][QComboBox] Fixed updating appearance of popup menu when changing the editable state of the combo box. Change-Id: Ib32f36cabd53c2c30d6256484a1eae131419960a Task-number: QTBUG-33537 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
This commit is contained in:
parent
29d3b9745b
commit
c4430ed023
@ -1704,8 +1704,6 @@ void QComboBox::setEditable(bool editable)
|
||||
if (isEditable() == editable)
|
||||
return;
|
||||
|
||||
d->updateDelegate();
|
||||
|
||||
QStyleOptionComboBox opt;
|
||||
initStyleOption(&opt);
|
||||
if (editable) {
|
||||
@ -1726,6 +1724,7 @@ void QComboBox::setEditable(bool editable)
|
||||
d->lineEdit = 0;
|
||||
}
|
||||
|
||||
d->updateDelegate();
|
||||
d->updateFocusPolicy();
|
||||
|
||||
d->viewContainer()->updateTopBottomMargin();
|
||||
|
@ -254,7 +254,7 @@ private:
|
||||
friend class QComboBox;
|
||||
};
|
||||
|
||||
class QComboMenuDelegate : public QAbstractItemDelegate
|
||||
class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate
|
||||
{ Q_OBJECT
|
||||
public:
|
||||
QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {}
|
||||
@ -283,7 +283,7 @@ private:
|
||||
// Note that this class is intentionally not using QStyledItemDelegate
|
||||
// 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
|
||||
class Q_AUTOTEST_EXPORT QComboBoxDelegate : public QItemDelegate
|
||||
{ Q_OBJECT
|
||||
public:
|
||||
QComboBoxDelegate(QObject *parent, QComboBox *cmb) : QItemDelegate(parent), mCombo(cmb) {}
|
||||
|
@ -160,6 +160,7 @@ private slots:
|
||||
void task_QTBUG_31146_popupCompletion();
|
||||
void keyboardSelection();
|
||||
void setCustomModelAndView();
|
||||
void updateDelegateOnEditableChange();
|
||||
};
|
||||
|
||||
class MyAbstractItemDelegate : public QAbstractItemDelegate
|
||||
@ -3049,5 +3050,32 @@ void tst_QComboBox::keyboardSelection()
|
||||
QCOMPARE(comboBox.currentText(), list.at(1));
|
||||
}
|
||||
|
||||
void tst_QComboBox::updateDelegateOnEditableChange()
|
||||
{
|
||||
|
||||
QComboBox box;
|
||||
box.addItem(QStringLiteral("Foo"));
|
||||
box.addItem(QStringLiteral("Bar"));
|
||||
box.setEditable(false);
|
||||
|
||||
QComboBoxPrivate *d = static_cast<QComboBoxPrivate *>(QComboBoxPrivate::get(&box));
|
||||
|
||||
{
|
||||
bool menuDelegateBefore = qobject_cast<QComboMenuDelegate *>(box.itemDelegate()) != 0;
|
||||
d->updateDelegate();
|
||||
bool menuDelegateAfter = qobject_cast<QComboMenuDelegate *>(box.itemDelegate()) != 0;
|
||||
QCOMPARE(menuDelegateAfter, menuDelegateBefore);
|
||||
}
|
||||
|
||||
box.setEditable(true);
|
||||
|
||||
{
|
||||
bool menuDelegateBefore = qobject_cast<QComboMenuDelegate *>(box.itemDelegate()) != 0;
|
||||
d->updateDelegate();
|
||||
bool menuDelegateAfter = qobject_cast<QComboMenuDelegate *>(box.itemDelegate()) != 0;
|
||||
QCOMPARE(menuDelegateAfter, menuDelegateBefore);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QComboBox)
|
||||
#include "tst_qcombobox.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user