I am trying to create a Qt main window application on Mac, but the height of the title bar of QDockWidget
is different from height of QToolbar
of central widget.
Is there a way to have same height for both?
I am trying to create a Qt main window application on Mac, but the height of the title bar of QDockWidget
is different from height of QToolbar
of central widget.
Is there a way to have same height for both?
Be aware that those sizes are style-dependant and may vary between platforms and, obviously, style used.
You can use this answer as a starting point and use QToolBar::setFixedHeight
to adequate the size to the style used:
const auto dw_style = dock_widget->style();
const int dw_titlebar_height = dw_style->pixelMetric(QStyle::PM_TitleBarHeight);
const int dw_titlebar_margin = dw_style->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
tool_bar->setFixedHeight(dw_titlebar_height - dw_titlebar_margin);
I don't have a Mac to test, but in Windows 10 it works.
Here the example without changing toolbar's height:
And here using the proposed tweak:
Hope it can help you.