int QDockWidgetLayout::titleHeight() const { QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); if (QWidget *title = widget(TitleBar)) return perp(verticalTitleBar, title->sizeHint()); QSize closeSize(0, 0); QSize floatSize(0, 0); if (QLayoutItem *item = item_list[CloseButton]) closeSize = item->widget()->sizeHint(); if (QLayoutItem *item = item_list[FloatButton]) floatSize = item->widget()->sizeHint(); int buttonHeight = qMax(perp(verticalTitleBar, closeSize), perp(verticalTitleBar, floatSize)); QFontMetrics titleFontMetrics = q->fontMetrics(); #ifdef Q_WS_MAC if (qobject_cast<QMacStyle *>(q->style())) { extern QHash<QByteArray, QFont> *qt_app_fonts_hash(); // qapplication.cpp QFont font = qt_app_fonts_hash()->value("QToolButton", q->font()); titleFontMetrics = QFontMetrics(font); } #endif int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); return qMax(buttonHeight + 2, titleFontMetrics.lineSpacing() + 2*mw); }
int QDockWidgetLayout::titleHeight() const { QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); if (QWidget *title = widgetForRole(TitleBar)) return perp(verticalTitleBar, title->sizeHint()); QSize closeSize(0, 0); QSize floatSize(0, 0); if (QLayoutItem *item = item_list[CloseButton]) closeSize = item->widget()->sizeHint(); if (QLayoutItem *item = item_list[FloatButton]) floatSize = item->widget()->sizeHint(); int buttonHeight = qMax(perp(verticalTitleBar, closeSize), perp(verticalTitleBar, floatSize)); QFontMetrics titleFontMetrics = q->fontMetrics(); #ifdef Q_WS_MAC if (qobject_cast<QMacStyle *>(q->style())) { //### this breaks on proxy styles. (But is this code still called?) QFont font = qt_app_fonts_hash()->value("QToolButton", q->font()); titleFontMetrics = QFontMetrics(font); } #endif int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); }
void QApplicationPrivate::initializeWidgetFontHash() { const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); if (!theme) return; FontHash *fontHash = qt_app_fonts_hash(); fontHash->clear(); if (const QFont *font = theme->font(QPlatformTheme::MenuFont)) fontHash->insert(QByteArrayLiteral("QMenu"), *font); if (const QFont *font = theme->font(QPlatformTheme::MenuBarFont)) fontHash->insert(QByteArrayLiteral("QMenuBar"), *font); if (const QFont *font = theme->font(QPlatformTheme::MenuItemFont)) fontHash->insert(QByteArrayLiteral("QMenuItem"), *font); if (const QFont *font = theme->font(QPlatformTheme::MessageBoxFont)) fontHash->insert(QByteArrayLiteral("QMessageBox"), *font); if (const QFont *font = theme->font(QPlatformTheme::LabelFont)) fontHash->insert(QByteArrayLiteral("QLabel"), *font); if (const QFont *font = theme->font(QPlatformTheme::TipLabelFont)) fontHash->insert(QByteArrayLiteral("QTipLabel"), *font); if (const QFont *font = theme->font(QPlatformTheme::TitleBarFont)) fontHash->insert(QByteArrayLiteral("QTitleBar"), *font); if (const QFont *font = theme->font(QPlatformTheme::StatusBarFont)) fontHash->insert(QByteArrayLiteral("QStatusBar"), *font); if (const QFont *font = theme->font(QPlatformTheme::MdiSubWindowTitleFont)) fontHash->insert(QByteArrayLiteral("QMdiSubWindowTitleBar"), *font); if (const QFont *font = theme->font(QPlatformTheme::DockWidgetTitleFont)) fontHash->insert(QByteArrayLiteral("QDockWidgetTitle"), *font); if (const QFont *font = theme->font(QPlatformTheme::PushButtonFont)) fontHash->insert(QByteArrayLiteral("QPushButton"), *font); if (const QFont *font = theme->font(QPlatformTheme::CheckBoxFont)) fontHash->insert(QByteArrayLiteral("QCheckBox"), *font); if (const QFont *font = theme->font(QPlatformTheme::RadioButtonFont)) fontHash->insert(QByteArrayLiteral("QRadioButton"), *font); if (const QFont *font = theme->font(QPlatformTheme::ToolButtonFont)) fontHash->insert(QByteArrayLiteral("QToolButton"), *font); if (const QFont *font = theme->font(QPlatformTheme::ItemViewFont)) fontHash->insert(QByteArrayLiteral("QAbstractItemView"), *font); if (const QFont *font = theme->font(QPlatformTheme::ListViewFont)) fontHash->insert(QByteArrayLiteral("QListViewFont"), *font); if (const QFont *font = theme->font(QPlatformTheme::HeaderViewFont)) fontHash->insert(QByteArrayLiteral("QHeaderViewFont"), *font); if (const QFont *font = theme->font(QPlatformTheme::ListBoxFont)) fontHash->insert(QByteArrayLiteral("QListBox"), *font); if (const QFont *font = theme->font(QPlatformTheme::ComboMenuItemFont)) fontHash->insert(QByteArrayLiteral("QComboMenuItemFont"), *font); if (const QFont *font = theme->font(QPlatformTheme::ComboLineEditFont)) fontHash->insert(QByteArrayLiteral("QComboLineEditFont"), *font); if (const QFont *font = theme->font(QPlatformTheme::SmallFont)) fontHash->insert(QByteArrayLiteral("QSmallFont"), *font); if (const QFont *font = theme->font(QPlatformTheme::MiniFont)) fontHash->insert(QByteArrayLiteral("QMiniFont"), *font); }