From 929509ea03b116588bdae38391377ec1ec976845 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Mon, 20 Oct 2014 18:44:13 +0200 Subject: QStyleSheetStyle: Don't interfere with QFontDialog The sample lineedit in Qt's own font dialog shouldn't have its font affected by stylesheets. Not only does this hampers the ability to preview the font, it actually overrides the font selection as that one is taken directly from the widget. Task-number: QTBUG-41513 Change-Id: I11d0bef8c7bf7bdae4cc08b6b9276d0fc14a75fb Reviewed-by: Olivier Goffart Reviewed-by: Frederik Gladhorn --- .../dialogs/qfontdialog/tst_qfontdialog.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp') diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index 22c84c2244..92ea7e5e57 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp +++ b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp @@ -36,6 +36,7 @@ #include +#include #include #include #include @@ -70,6 +71,10 @@ private slots: void setFont(); void task256466_wrongStyle(); void setNonStandardFontSize(); +#ifndef QT_NO_STYLE_STYLESHEET + void qtbug_41513_stylesheetStyle(); +#endif + private: void runSlotWithFailsafeTimer(const char *member); @@ -201,6 +206,31 @@ void tst_QFontDialog::setNonStandardFontSize() { runSlotWithFailsafeTimer(SLOT(testNonStandardFontSize())); } +#ifndef QT_NO_STYLE_STYLESHEET +static const QString offendingStyleSheet = QStringLiteral("* { font-family: \"QtBidiTestFont\"; }"); + +void tst_QFontDialog::qtbug_41513_stylesheetStyle() +{ + if (QFontDatabase::addApplicationFont(QFINDTESTDATA("test.ttf")) < 0) + QSKIP("Test fonts not found."); + if (QFontDatabase::addApplicationFont(QFINDTESTDATA("testfont.ttf")) < 0) + QSKIP("Test fonts not found."); + QFont testFont = QFont(QStringLiteral("QtsSpecialTestFont")); + qApp->setStyleSheet(offendingStyleSheet); + bool accepted = false; + QTimer::singleShot(2000, this, SLOT(postKeyReturn())); + QFont resultFont = QFontDialog::getFont(&accepted, testFont, + QApplication::activeWindow(), + QLatin1String("QFontDialog - Stylesheet Test"), + QFontDialog::DontUseNativeDialog); + QVERIFY(accepted); + + QCOMPARE(resultFont, testFont); + + // reset stylesheet + qApp->setStyleSheet(QString()); +} +#endif // QT_NO_STYLE_STYLESHEET void tst_QFontDialog::testNonStandardFontSize() { -- cgit v1.2.3