QCombobox: propagate the palette to the embedded line edit

Let the new created embedded QLineEdit use the palette from QCombobox,
when calling [setEditable(true)]

Fixes: QTBUG-81533
Pick-to: 5.15
Change-Id: Ia406dd8122a348e185f0e94d027646b95eeaa76e
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Wang Chuan 2020-10-25 21:38:19 +08:00
parent be37937614
commit 231be2e0a1
2 changed files with 28 additions and 0 deletions

View File

@ -1781,6 +1781,7 @@ void QComboBox::setEditable(bool editable)
view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
}
QLineEdit *le = new QLineEdit(this);
le->setPalette(palette());
setLineEdit(le);
} else {
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {

View File

@ -166,6 +166,7 @@ private slots:
void inputMethodUpdate();
void task_QTBUG_52027_mapCompleterIndex();
void checkMenuItemPosWhenStyleSheetIsSet();
void checkEmbeddedLineEditWhenStyleSheetIsSet();
private:
PlatformInputContext m_platformInputContext;
@ -3515,5 +3516,31 @@ void tst_QComboBox::checkMenuItemPosWhenStyleSheetIsSet()
qApp->setStyleSheet(oldCss);
}
void tst_QComboBox::checkEmbeddedLineEditWhenStyleSheetIsSet()
{
QString newCss = "QWidget { background-color: red; color: white; }";
QString oldCss = qApp->styleSheet();
qApp->setStyleSheet(newCss);
QWidget topLevel;
auto layout = new QVBoxLayout(&topLevel);
topLevel.setLayout(layout);
auto comboBox = new QComboBox;
layout->addWidget(comboBox);
topLevel.show();
comboBox->setEditable(true);
QApplication::setActiveWindow(&topLevel);
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
QImage grab = comboBox->grab().toImage();
auto color = grab.pixelColor(grab.rect().center());
QVERIFY(color.red() > 240);
QVERIFY(color.green() < 20);
QVERIFY(color.blue() < 20);
qApp->setStyleSheet(oldCss);
}
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"