pineweasel
pineweasel

Reputation: 123

Qt: How to get pixel metrics for a particular widget

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?

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);

Upvotes: 2

Views: 1860

Answers (1)

tjw
tjw

Reputation: 11

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

Upvotes: 1

Related Questions