Add simple palette to tst_QWidget
When a widget's palette has different active / inactive colors, multiple paint events can occur. This makes tst_QWidget functions fail when they expect a spcific amount of paint events and the platform theme provides a palette with active / inactive differences. This patch adds a function to populate test widgets with a simple palette, to prevent multiple paint events. Change-Id: If9b2faedcc5ca87ba24991cedd5e4ac927b02644 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 1576f827214cca8a2233f3c81e7d0e3d89eb8007) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9f1d4b2e52
commit
08f754d923
@ -437,6 +437,7 @@ private:
|
|||||||
const bool m_windowsAnimationsEnabled;
|
const bool m_windowsAnimationsEnabled;
|
||||||
QPointingDevice *m_touchScreen;
|
QPointingDevice *m_touchScreen;
|
||||||
const int m_fuzz;
|
const int m_fuzz;
|
||||||
|
QPalette simplePalette();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Testing get/set functions
|
// Testing get/set functions
|
||||||
@ -4520,6 +4521,7 @@ void tst_QWidget::optimizedResizeMove()
|
|||||||
if (m_platform == QStringLiteral("wayland"))
|
if (m_platform == QStringLiteral("wayland"))
|
||||||
QSKIP("Wayland: This fails. Figure out why.");
|
QSKIP("Wayland: This fails. Figure out why.");
|
||||||
QWidget parent;
|
QWidget parent;
|
||||||
|
parent.setPalette(simplePalette());
|
||||||
parent.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
parent.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
parent.resize(400, 400);
|
parent.resize(400, 400);
|
||||||
|
|
||||||
@ -4604,6 +4606,7 @@ void tst_QWidget::optimizedResize_topLevel()
|
|||||||
if (QHighDpiScaling::isActive())
|
if (QHighDpiScaling::isActive())
|
||||||
QSKIP("Skip due to rounding errors in the regions.");
|
QSKIP("Skip due to rounding errors in the regions.");
|
||||||
StaticWidget topLevel;
|
StaticWidget topLevel;
|
||||||
|
topLevel.setPalette(simplePalette());
|
||||||
topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
topLevel.gotPaintEvent = false;
|
topLevel.gotPaintEvent = false;
|
||||||
topLevel.show();
|
topLevel.show();
|
||||||
@ -5215,6 +5218,7 @@ void tst_QWidget::update()
|
|||||||
Q_CHECK_PAINTEVENTS
|
Q_CHECK_PAINTEVENTS
|
||||||
|
|
||||||
UpdateWidget w;
|
UpdateWidget w;
|
||||||
|
w.setPalette(simplePalette());
|
||||||
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
w.resize(100, 100);
|
w.resize(100, 100);
|
||||||
centerOnScreen(&w);
|
centerOnScreen(&w);
|
||||||
@ -5228,6 +5232,7 @@ void tst_QWidget::update()
|
|||||||
w.reset();
|
w.reset();
|
||||||
|
|
||||||
UpdateWidget child(&w);
|
UpdateWidget child(&w);
|
||||||
|
child.setPalette(simplePalette());
|
||||||
child.setGeometry(10, 10, 80, 80);
|
child.setGeometry(10, 10, 80, 80);
|
||||||
child.show();
|
child.show();
|
||||||
|
|
||||||
@ -5299,6 +5304,7 @@ void tst_QWidget::update()
|
|||||||
|
|
||||||
// overlapping sibling
|
// overlapping sibling
|
||||||
UpdateWidget sibling(&w);
|
UpdateWidget sibling(&w);
|
||||||
|
sibling.setPalette(simplePalette());
|
||||||
child.setGeometry(10, 10, 20, 20);
|
child.setGeometry(10, 10, 20, 20);
|
||||||
sibling.setGeometry(15, 15, 20, 20);
|
sibling.setGeometry(15, 15, 20, 20);
|
||||||
sibling.show();
|
sibling.show();
|
||||||
@ -5378,9 +5384,11 @@ void tst_QWidget::isOpaque()
|
|||||||
{
|
{
|
||||||
#ifndef Q_OS_MACOS
|
#ifndef Q_OS_MACOS
|
||||||
QWidget w;
|
QWidget w;
|
||||||
|
w.setPalette(simplePalette());
|
||||||
QVERIFY(::isOpaque(&w));
|
QVERIFY(::isOpaque(&w));
|
||||||
|
|
||||||
QWidget child(&w);
|
QWidget child(&w);
|
||||||
|
child.setPalette(simplePalette());
|
||||||
QVERIFY(!::isOpaque(&child));
|
QVERIFY(!::isOpaque(&child));
|
||||||
|
|
||||||
child.setAutoFillBackground(true);
|
child.setAutoFillBackground(true);
|
||||||
@ -5462,6 +5470,7 @@ void tst_QWidget::scroll()
|
|||||||
const int h = qMin(500, screen->availableGeometry().height() / 2);
|
const int h = qMin(500, screen->availableGeometry().height() / 2);
|
||||||
|
|
||||||
UpdateWidget updateWidget;
|
UpdateWidget updateWidget;
|
||||||
|
updateWidget.setPalette(simplePalette());
|
||||||
updateWidget.resize(w, h);
|
updateWidget.resize(w, h);
|
||||||
updateWidget.reset();
|
updateWidget.reset();
|
||||||
updateWidget.move(m_availableTopLeft);
|
updateWidget.move(m_availableTopLeft);
|
||||||
@ -8563,6 +8572,7 @@ void tst_QWidget::updateWhileMinimized()
|
|||||||
QSKIP("Platform does not support showMinimized()");
|
QSKIP("Platform does not support showMinimized()");
|
||||||
#endif
|
#endif
|
||||||
UpdateWidget widget;
|
UpdateWidget widget;
|
||||||
|
widget.setPalette(simplePalette());
|
||||||
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
// Filter out activation change and focus events to avoid update() calls in QWidget.
|
// Filter out activation change and focus events to avoid update() calls in QWidget.
|
||||||
widget.updateOnActivationChangeAndFocusIn = false;
|
widget.updateOnActivationChangeAndFocusIn = false;
|
||||||
@ -9136,6 +9146,7 @@ void tst_QWidget::doubleRepaint()
|
|||||||
QSKIP("Not having window server access causes the wrong number of repaints to be issues");
|
QSKIP("Not having window server access causes the wrong number of repaints to be issues");
|
||||||
#endif
|
#endif
|
||||||
UpdateWidget widget;
|
UpdateWidget widget;
|
||||||
|
widget.setPalette(simplePalette());
|
||||||
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
centerOnScreen(&widget);
|
centerOnScreen(&widget);
|
||||||
widget.setFocusPolicy(Qt::StrongFocus);
|
widget.setFocusPolicy(Qt::StrongFocus);
|
||||||
@ -9167,6 +9178,7 @@ void tst_QWidget::resizeInPaintEvent()
|
|||||||
QWidget window;
|
QWidget window;
|
||||||
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
UpdateWidget widget(&window);
|
UpdateWidget widget(&window);
|
||||||
|
widget.setPalette(simplePalette());
|
||||||
window.resize(200, 200);
|
window.resize(200, 200);
|
||||||
window.show();
|
window.show();
|
||||||
QApplication::setActiveWindow(&window);
|
QApplication::setActiveWindow(&window);
|
||||||
@ -9298,6 +9310,7 @@ public slots:
|
|||||||
void tst_QWidget::setMaskInResizeEvent()
|
void tst_QWidget::setMaskInResizeEvent()
|
||||||
{
|
{
|
||||||
UpdateWidget w;
|
UpdateWidget w;
|
||||||
|
w.setPalette(simplePalette());
|
||||||
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
w.reset();
|
w.reset();
|
||||||
w.resize(200, 200);
|
w.resize(200, 200);
|
||||||
@ -9377,6 +9390,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBackingStore()
|
|||||||
QSKIP("We don't support immediate repaint right after show on other platforms.");
|
QSKIP("We don't support immediate repaint right after show on other platforms.");
|
||||||
|
|
||||||
QScopedPointer<UpdateWidget> widget(new UpdateWidget);
|
QScopedPointer<UpdateWidget> widget(new UpdateWidget);
|
||||||
|
widget->setPalette(simplePalette());
|
||||||
widget->setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
widget->setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
centerOnScreen(widget.data());
|
centerOnScreen(widget.data());
|
||||||
widget->show();
|
widget->show();
|
||||||
@ -9828,6 +9842,7 @@ void tst_QWidget::setClearAndResizeMask()
|
|||||||
QSKIP("Wayland: This fails. Figure out why.");
|
QSKIP("Wayland: This fails. Figure out why.");
|
||||||
|
|
||||||
UpdateWidget topLevel;
|
UpdateWidget topLevel;
|
||||||
|
topLevel.setPalette(simplePalette());
|
||||||
topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
topLevel.resize(160, 160);
|
topLevel.resize(160, 160);
|
||||||
centerOnScreen(&topLevel);
|
centerOnScreen(&topLevel);
|
||||||
@ -9862,6 +9877,7 @@ void tst_QWidget::setClearAndResizeMask()
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateWidget child(&topLevel);
|
UpdateWidget child(&topLevel);
|
||||||
|
child.setPalette(simplePalette());
|
||||||
child.setAutoFillBackground(true); // NB! Opaque child.
|
child.setAutoFillBackground(true); // NB! Opaque child.
|
||||||
child.setPalette(Qt::red);
|
child.setPalette(Qt::red);
|
||||||
child.resize(100, 100);
|
child.resize(100, 100);
|
||||||
@ -10662,6 +10678,7 @@ void tst_QWidget::focusWidget_task254563()
|
|||||||
void tst_QWidget::destroyBackingStore()
|
void tst_QWidget::destroyBackingStore()
|
||||||
{
|
{
|
||||||
UpdateWidget w;
|
UpdateWidget w;
|
||||||
|
w.setPalette(simplePalette());
|
||||||
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
|
||||||
centerOnScreen(&w);
|
centerOnScreen(&w);
|
||||||
w.reset();
|
w.reset();
|
||||||
@ -12368,6 +12385,7 @@ void tst_QWidget::resizeStaticContentsChildWidget_QTBUG35282()
|
|||||||
widget.resize(200,200);
|
widget.resize(200,200);
|
||||||
|
|
||||||
UpdateWidget childWidget(&widget);
|
UpdateWidget childWidget(&widget);
|
||||||
|
childWidget.setPalette(simplePalette());
|
||||||
childWidget.setAttribute(Qt::WA_StaticContents);
|
childWidget.setAttribute(Qt::WA_StaticContents);
|
||||||
childWidget.setAttribute(Qt::WA_OpaquePaintEvent);
|
childWidget.setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
childWidget.setGeometry(250, 250, 500, 500);
|
childWidget.setGeometry(250, 250, 500, 500);
|
||||||
@ -12964,6 +12982,35 @@ void tst_QWidget::activateWhileModalHidden()
|
|||||||
QCOMPARE(QApplication::activeWindow(), &window);
|
QCOMPARE(QApplication::activeWindow(), &window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a simple palette to prevent multiple paint events
|
||||||
|
QPalette tst_QWidget::simplePalette()
|
||||||
|
{
|
||||||
|
static QPalette simplePalette = []{
|
||||||
|
const QColor windowText = Qt::black;
|
||||||
|
const QColor backGround = QColor(239, 239, 239);
|
||||||
|
const QColor light = backGround.lighter(150);
|
||||||
|
const QColor mid = (backGround.darker(130));
|
||||||
|
const QColor midLight = mid.lighter(110);
|
||||||
|
const QColor base = Qt::white;
|
||||||
|
const QColor dark = backGround.darker(150);
|
||||||
|
const QColor text = Qt::black;
|
||||||
|
const QColor highlight = QColor(48, 140, 198);
|
||||||
|
const QColor hightlightedText = Qt::white;
|
||||||
|
const QColor button = backGround;
|
||||||
|
const QColor shadow = dark.darker(135);
|
||||||
|
|
||||||
|
QPalette defaultPalette(windowText, backGround, light, dark, mid, text, base);
|
||||||
|
defaultPalette.setBrush(QPalette::Midlight, midLight);
|
||||||
|
defaultPalette.setBrush(QPalette::Button, button);
|
||||||
|
defaultPalette.setBrush(QPalette::Shadow, shadow);
|
||||||
|
defaultPalette.setBrush(QPalette::HighlightedText, hightlightedText);
|
||||||
|
defaultPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight);
|
||||||
|
return defaultPalette;
|
||||||
|
}();
|
||||||
|
|
||||||
|
return simplePalette;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
void tst_QWidget::showFullscreenAndroid()
|
void tst_QWidget::showFullscreenAndroid()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user