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 <ogoffart@woboq.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
This commit is contained in:
parent
8c4deff51c
commit
929509ea03
@ -322,6 +322,7 @@ void QFontDialogPrivate::init()
|
||||
|
||||
familyList->setFocus();
|
||||
retranslateStrings();
|
||||
sampleEdit->setObjectName(QLatin1String("qt_fontDialog_sampleEdit"));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>test.ttf</file>
|
||||
<file alias="test.ttf">../../../shared/resources/test.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>testfont_bold_italic.ttf</file>
|
||||
<file>testfont.ttf</file>
|
||||
<file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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
|
||||
|
6
tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc
Normal file
6
tests/auto/widgets/dialogs/qfontdialog/testfonts.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="test.ttf">../../../shared/resources/test.ttf</file>
|
||||
<file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -36,6 +36,7 @@
|
||||
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qfontdatabase.h>
|
||||
#include <qfontinfo.h>
|
||||
#include <qtimer.h>
|
||||
#include <qmainwindow.h>
|
||||
@ -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()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user