diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-09-22 12:26:21 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2009-09-23 13:15:41 (GMT) |
commit | 2966b2a95b0d7d161a6dc1a6edab3d6aa6edf004 (patch) | |
tree | da22289d8ae4a39e621202952a56418da242cfc5 /tests | |
parent | 7dcf984f85a3a75ce4c078cc931bd9d2304bc235 (diff) | |
download | Qt-2966b2a95b0d7d161a6dc1a6edab3d6aa6edf004.zip Qt-2966b2a95b0d7d161a6dc1a6edab3d6aa6edf004.tar.gz Qt-2966b2a95b0d7d161a6dc1a6edab3d6aa6edf004.tar.bz2 |
When using style sheets, the focus flag was not propagated to the children of
complex widgets.
Reviewed-by: Olivier
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp index e7d804a..e8fbd86 100644 --- a/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -95,6 +95,7 @@ private slots: void embeddedFonts(); void opaquePaintEvent_data(); void opaquePaintEvent(); + void complexWidgetFocus(); void task188195_baseBackground(); void task232085_spinBoxLineEditBg(); @@ -1447,6 +1448,60 @@ void tst_QStyleSheetStyle::opaquePaintEvent() QCOMPARE(cl.autoFillBackground(), !styled ); } +void tst_QStyleSheetStyle::complexWidgetFocus() +{ + // This test is a simplified version of the focusColors() test above. + + // Tests if colors can be changed by altering the focus of the widget. + // To avoid messy pixel-by-pixel comparison, we assume that the goal + // is reached if at least ten pixels of the right color can be found in + // the image. + // For this reason, we use unusual and extremely ugly colors! :-) + + QDialog frame; + // We only want to test the buttons colors. + frame.setStyleSheet("*:focus { background: black; color: black } " + "QSpinBox::up-button:focus, QSpinBox::down-button:focus { width: 15px; height: 15px; background: #e8ff66; color: #ff0084 } " + "QSpinBox::up-arrow:focus, QSpinBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084 } " + "QComboBox::drop-down:focus { background: #e8ff66; color: #ff0084 } " + "QComboBox::down-arrow:focus { width: 7px; height: 7px; background: #ff0084; color: #e8ff66 }"); + + QList<QWidget *> widgets; + widgets << new QSpinBox; + widgets << new QComboBox; + + QLayout* layout = new QGridLayout; + layout->addWidget(new QLineEdit); // Avoids initial focus. + foreach (QWidget *widget, widgets) + layout->addWidget(widget); + frame.setLayout(layout); + + frame.show(); + QTest::qWaitForWindowShown(&frame); + QApplication::setActiveWindow(&frame); + foreach (QWidget *widget, widgets) { + widget->setFocus(); + QApplication::processEvents(); + + QImage image(frame.width(), frame.height(), QImage::Format_ARGB32); + frame.render(&image); + if (image.depth() < 24) { + QSKIP("Test doesn't support color depth < 24", SkipAll); + } + + QVERIFY2(testForColors(image, QColor(0xe8, 0xff, 0x66)), + (QString::fromLatin1(widget->metaObject()->className()) + + " did not contain background color #e8ff66, using style " + + QString::fromLatin1(qApp->style()->metaObject()->className())) + .toLocal8Bit().constData()); + QVERIFY2(testForColors(image, QColor(0xff, 0x00, 0x84)), + (QString::fromLatin1(widget->metaObject()->className()) + + " did not contain text color #ff0084, using style " + + QString::fromLatin1(qApp->style()->metaObject()->className())) + .toLocal8Bit().constData()); + } +} + void tst_QStyleSheetStyle::task188195_baseBackground() { QTreeView tree; |