QDockWidget: Use theme font for title

While the QPA theme provides support for dock widgets
title font we never use it.

This is a very similar solution to what we do in
QMdiSubWindow, setting the platform theme font at
few specific points.

This patch also fixes the dock window title font on
macOS, as queried in QCoreTextFontDatabase.

Change-Id: Ie264e4e83e0d3d1e8f78bd378359f3063cc1d525
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Gabriel de Dietrich 2018-01-26 18:36:35 -08:00
parent 347cfa00a2
commit 3de8e74d77
3 changed files with 9 additions and 1 deletions

View File

@ -686,9 +686,11 @@ static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f)
return kCTFontUIFontWindowTitle; return kCTFontUIFontWindowTitle;
case QPlatformTheme::MdiSubWindowTitleFont: case QPlatformTheme::MdiSubWindowTitleFont:
case QPlatformTheme::DockWidgetTitleFont:
return kCTFontUIFontSystem; return kCTFontUIFontSystem;
case QPlatformTheme::DockWidgetTitleFont:
return kCTFontUIFontSmallSystem;
case QPlatformTheme::PushButtonFont: case QPlatformTheme::PushButtonFont:
return kCTFontUIFontPushButton; return kCTFontUIFontPushButton;

View File

@ -653,6 +653,8 @@ void QDockWidgetPrivate::init()
QObject::connect(button, SIGNAL(clicked()), q, SLOT(close())); QObject::connect(button, SIGNAL(clicked()), q, SLOT(close()));
layout->setWidgetForRole(QDockWidgetLayout::CloseButton, button); layout->setWidgetForRole(QDockWidgetLayout::CloseButton, button);
font = QApplication::font("QDockWidgetTitle");
#ifndef QT_NO_ACTION #ifndef QT_NO_ACTION
toggleViewAction = new QAction(q); toggleViewAction = new QAction(q);
toggleViewAction->setCheckable(true); toggleViewAction->setCheckable(true);
@ -685,6 +687,7 @@ void QDockWidget::initStyleOption(QStyleOptionDockWidget *option) const
// If we are in a floating tab, init from the parent because the attributes and the geometry // If we are in a floating tab, init from the parent because the attributes and the geometry
// of the title bar should be taken from the floating window. // of the title bar should be taken from the floating window.
option->initFrom(floatingTab && !isFloating() ? parentWidget() : this); option->initFrom(floatingTab && !isFloating() ? parentWidget() : this);
option->fontMetrics = QFontMetrics(d->font);
option->rect = dwlayout->titleArea(); option->rect = dwlayout->titleArea();
option->title = d->fixedWindowTitle; option->title = d->fixedWindowTitle;
option->closable = hasFeature(this, QDockWidget::DockWidgetClosable); option->closable = hasFeature(this, QDockWidget::DockWidgetClosable);
@ -1481,6 +1484,7 @@ void QDockWidget::paintEvent(QPaintEvent *event)
// the title may wish to extend out to all sides (eg. Vista style) // the title may wish to extend out to all sides (eg. Vista style)
QStyleOptionDockWidget titleOpt; QStyleOptionDockWidget titleOpt;
initStyleOption(&titleOpt); initStyleOption(&titleOpt);
p.setFont(d_func()->font);
p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt); p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt);
} }
} }

View File

@ -99,6 +99,8 @@ public:
QDockWidget::DockWidgetFeatures features; QDockWidget::DockWidgetFeatures features;
Qt::DockWidgetAreas allowedAreas; Qt::DockWidgetAreas allowedAreas;
QFont font;
#ifndef QT_NO_ACTION #ifndef QT_NO_ACTION
QAction *toggleViewAction; QAction *toggleViewAction;
#endif #endif