From 929509ea03b116588bdae38391377ec1ec976845 Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Mon, 20 Oct 2014 18:44:13 +0200 Subject: [PATCH] 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 --- src/widgets/dialogs/qfontdialog.cpp | 1 + src/widgets/styles/qstylesheetstyle.cpp | 4 +++ tests/auto/gui/text/qglyphrun/qglyphrun.pro | 13 ++++---- tests/auto/gui/text/qglyphrun/testdata.qrc | 2 +- tests/auto/gui/text/qrawfont/qrawfont.pro | 8 ++--- tests/auto/gui/text/qrawfont/testdata.qrc | 2 +- .../qglyphrun => shared/resources}/test.ttf | Bin .../resources}/testfont.ttf | Bin .../dialogs/qfontdialog/qfontdialog.pro | 2 ++ .../widgets/dialogs/qfontdialog/testfonts.qrc | 6 ++++ .../dialogs/qfontdialog/tst_qfontdialog.cpp | 30 ++++++++++++++++++ 11 files changed, 53 insertions(+), 15 deletions(-) rename tests/auto/{gui/text/qglyphrun => shared/resources}/test.ttf (100%) rename tests/auto/{gui/text/qrawfont => shared/resources}/testfont.ttf (100%) create mode 100644 tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index 109b7268807..d12b109d9fe 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -322,6 +322,7 @@ void QFontDialogPrivate::init() familyList->setFocus(); retranslateStrings(); + sampleEdit->setObjectName(QLatin1String("qt_fontDialog_sampleEdit")); } /*! diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index a9e13bad499..e9f20de8425 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -5828,6 +5828,10 @@ bool QStyleSheetStyle::event(QEvent *e) void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const { + // Qt's fontDialog relies on the font of the sample edit for its selection, + // we should never override it. + if (w->objectName() == QLatin1String("qt_fontDialog_sampleEdit")) + return; QWidget *container = containerWidget(w); QRenderRule rule = renderRule(container, PseudoElement_None, PseudoClass_Active | PseudoClass_Enabled | extendedPseudoClass(container)); diff --git a/tests/auto/gui/text/qglyphrun/qglyphrun.pro b/tests/auto/gui/text/qglyphrun/qglyphrun.pro index 0993a5c49c0..b7d9f164c93 100644 --- a/tests/auto/gui/text/qglyphrun/qglyphrun.pro +++ b/tests/auto/gui/text/qglyphrun/qglyphrun.pro @@ -8,14 +8,13 @@ linux: CONFIG += insignificant_test SOURCES += \ tst_qglyphrun.cpp -android { + +wince* { + additionalFiles.files = test.ttf + additionalFiles.path = ../../../shared/resources/ + DEPLOYMENT += additionalFiles +} else { RESOURCES += \ testdata.qrc } -wince* { - additionalFiles.files = test.ttf - additionalFiles.path = . - DEPLOYMENT += additionalFiles -} - diff --git a/tests/auto/gui/text/qglyphrun/testdata.qrc b/tests/auto/gui/text/qglyphrun/testdata.qrc index c4e237ad2f2..25cadc477e8 100644 --- a/tests/auto/gui/text/qglyphrun/testdata.qrc +++ b/tests/auto/gui/text/qglyphrun/testdata.qrc @@ -1,5 +1,5 @@ - test.ttf + ../../../shared/resources/test.ttf diff --git a/tests/auto/gui/text/qrawfont/qrawfont.pro b/tests/auto/gui/text/qrawfont/qrawfont.pro index 1891e7a9bfc..20da2e9a224 100644 --- a/tests/auto/gui/text/qrawfont/qrawfont.pro +++ b/tests/auto/gui/text/qrawfont/qrawfont.pro @@ -7,9 +7,5 @@ QT = core core-private gui gui-private testlib SOURCES += \ tst_qrawfont.cpp -TESTDATA += testfont_bold_italic.ttf testfont.ttf - -android { - RESOURCES += \ - testdata.qrc -} +RESOURCES += \ + testdata.qrc diff --git a/tests/auto/gui/text/qrawfont/testdata.qrc b/tests/auto/gui/text/qrawfont/testdata.qrc index 7bea0d5a399..8f8e32ed246 100644 --- a/tests/auto/gui/text/qrawfont/testdata.qrc +++ b/tests/auto/gui/text/qrawfont/testdata.qrc @@ -1,6 +1,6 @@ testfont_bold_italic.ttf - testfont.ttf + ../../../shared/resources/testfont.ttf diff --git a/tests/auto/gui/text/qglyphrun/test.ttf b/tests/auto/shared/resources/test.ttf similarity index 100% rename from tests/auto/gui/text/qglyphrun/test.ttf rename to tests/auto/shared/resources/test.ttf diff --git a/tests/auto/gui/text/qrawfont/testfont.ttf b/tests/auto/shared/resources/testfont.ttf similarity index 100% rename from tests/auto/gui/text/qrawfont/testfont.ttf rename to tests/auto/shared/resources/testfont.ttf diff --git a/tests/auto/widgets/dialogs/qfontdialog/qfontdialog.pro b/tests/auto/widgets/dialogs/qfontdialog/qfontdialog.pro index 8116fe379aa..dc1702971e7 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/qfontdialog.pro +++ b/tests/auto/widgets/dialogs/qfontdialog/qfontdialog.pro @@ -7,6 +7,8 @@ QT += core-private gui-private SOURCES += tst_qfontdialog.cpp +RESOURCES += testfonts.qrc + mac { # ### fixme # OBJECTIVE_SOURCES += tst_qfontdialog_mac_helpers.mm diff --git a/tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc b/tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc new file mode 100644 index 00000000000..cdfa287b392 --- /dev/null +++ b/tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc @@ -0,0 +1,6 @@ + + + ../../../shared/resources/test.ttf + ../../../shared/resources/testfont.ttf + + diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index 22c84c22449..92ea7e5e571 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() {