开发者

Qt: How to get pixel metrics for a particular widget

开发者 https://www.devze.com 2023-02-10 17:26 出处:网络
I have a QWidget, which may be a window, with a title bar and frame, or it may be a simple control such as a button or a frame.

I have a QWidget, which may be a window, with a title bar and frame, or it may be a simple control such as a button or a frame.

How do I write code to query the title bar height such that I get the right result - i.e. the system title bar height if it's a window with one, or 0 otherwise?

开发者_C百科

I tried using the QStyle pixel metrics, but it always returns the system value:

QStyleOptionTitleBar option;
option.initFrom(widget);
captionHeight = widget->style()->pixelMetric(QStyle::PM_TitleBarHeight, &option, widget);


Use widget::isWindow() to tell if the widget is in it's own window - then use what you've got

0

精彩评论

暂无评论...
验证码 换一张
取 消