How to find the height of a QDockWidget title bar?

蹲街弑〆低调 提交于 2020-01-03 10:44:49

问题


I'm trying to find the height of a QDockWidget title bar in order to do some intelligent sizing of a custom layout, but the title bar is not a separate widget, it's built into the private layout of the dock widget, and there is no member to access it. Is there some other way to find its height?


回答1:


Yes, you can find the title bar's height using the pixelMetric member function of the dock's QStyle element. You'll probably also want to query the margin as well since it adds space around the title bar and the layout will need to be aware of it. Example:

QDockWidget * myDock = new QDockWidget;
int titleBarHeight = myDock->style()->pixelMetric(QStyle::PM_TitleBarHeight);
int titleBarMargin = myDock->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);



回答2:


You can always run QObject::findChild wih a suitable type or object name to find otherwise inaccessible children.



来源:https://stackoverflow.com/questions/26411989/how-to-find-the-height-of-a-qdockwidget-title-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!