1

I use the following code:

int SWStyle::pixelMetric( PixelMetric which, const QStyleOption *option, const QWidget *widget ) const
{
    switch (which)
    {
    case PM_DefaultFrameWidth:
        return 1;
    case PM_TitleBarHeight:
        return 80;
    default:
        return QCleanlooksStyle::pixelMetric(which, option, widget);
    }
}

--------------------------------------------
myQdockWidget->setStyle(new SWStyle);

to change the height of title bar, but it doesn't work, it can change frame width.

could title bar height of QDockWidget be changed?

user497032
  • 75
  • 1
  • 10

1 Answers1

1

Looking at the Qt source (version 5.8) it doesn't appear to use PM_TitleBarHeight when calculating the title height. Instead it uses a combination of QFontMetrics::height() and the pixel metric for QStyle::PM_DockWidgetTitleMargin (from the Qt source)...

QFontMetrics titleFontMetrics = q->fontMetrics();
int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);

return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw);

So updating your SWStyle::pixelMetric override to provide a case for QStyle::PM_DockWidgetTitleMargin might be a good starting point.

Apart from that you can always pass your own custom title widget to QDockWidget::setTitleBarWidget.

G.M.
  • 12,232
  • 2
  • 15
  • 18