QGuiApplication: Add fontChanged signal
This removes the need to install an event filter on qApp just for this. A similar thing was done with setPalette to reduce the number of event filters in e.g. SystemPalette and Quick Controls. [ChangeLog][QtGui][QGuiApplication] Added fontChanged signal Change-Id: Ifa843aa42b91ac63ab17c3b064ac0e764aac77d3 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
This commit is contained in:
parent
d51dde6c67
commit
e5b422382a
@ -3109,6 +3109,15 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
|
||||
windowGeometrySpecification.applyTo(window);
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.11
|
||||
\fn void QGuiApplication::fontChanged(const QFont &font)
|
||||
|
||||
This signal is emitted when the \a font of the application changes.
|
||||
|
||||
\sa font()
|
||||
*/
|
||||
|
||||
/*!
|
||||
Returns the default application font.
|
||||
|
||||
@ -3130,11 +3139,16 @@ QFont QGuiApplication::font()
|
||||
void QGuiApplication::setFont(const QFont &font)
|
||||
{
|
||||
QMutexLocker locker(&applicationFontMutex);
|
||||
const bool emitChange = !QGuiApplicationPrivate::app_font
|
||||
|| (*QGuiApplicationPrivate::app_font != font);
|
||||
if (!QGuiApplicationPrivate::app_font)
|
||||
QGuiApplicationPrivate::app_font = new QFont(font);
|
||||
else
|
||||
*QGuiApplicationPrivate::app_font = font;
|
||||
applicationResourceFlags |= ApplicationFontExplicitlySet;
|
||||
|
||||
if (emitChange && qGuiApp)
|
||||
emit qGuiApp->fontChanged(*QGuiApplicationPrivate::app_font);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -187,6 +187,7 @@ Q_SIGNALS:
|
||||
#endif
|
||||
void paletteChanged(const QPalette &pal);
|
||||
void applicationDisplayNameChanged();
|
||||
void fontChanged(const QFont &font);
|
||||
|
||||
protected:
|
||||
bool event(QEvent *) override;
|
||||
|
@ -68,6 +68,7 @@ private slots:
|
||||
void changeFocusWindow();
|
||||
void keyboardModifiers();
|
||||
void palette();
|
||||
void font();
|
||||
void modalWindow();
|
||||
void quitOnLastWindowClosed();
|
||||
void quitOnLastWindowClosedMulti();
|
||||
@ -524,6 +525,31 @@ void tst_QGuiApplication::palette()
|
||||
QCOMPARE(signalSpy.count(), 2);
|
||||
}
|
||||
|
||||
void tst_QGuiApplication::font()
|
||||
{
|
||||
int argc = 1;
|
||||
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
|
||||
QGuiApplication app(argc, argv);
|
||||
QSignalSpy signalSpy(&app, SIGNAL(fontChanged(QFont)));
|
||||
|
||||
QFont oldFont = QGuiApplication::font();
|
||||
QFont newFont = QFont("BogusFont", 33);
|
||||
|
||||
QGuiApplication::setFont(newFont);
|
||||
QCOMPARE(QGuiApplication::font(), newFont);
|
||||
QCOMPARE(signalSpy.count(), 1);
|
||||
QCOMPARE(signalSpy.at(0).at(0), QVariant(newFont));
|
||||
|
||||
QGuiApplication::setFont(oldFont);
|
||||
QCOMPARE(QGuiApplication::font(), oldFont);
|
||||
QCOMPARE(signalSpy.count(), 2);
|
||||
QCOMPARE(signalSpy.at(1).at(0), QVariant(oldFont));
|
||||
|
||||
QGuiApplication::setFont(oldFont);
|
||||
QCOMPARE(QGuiApplication::font(), oldFont);
|
||||
QCOMPARE(signalSpy.count(), 2);
|
||||
}
|
||||
|
||||
class BlockableWindow : public QWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user