[Qt-interest] QMacStyle::pixelMetric with QStyle::PM_TitleBarHeight gives bad result?

John Weeks john at wavemetrics.com
Wed Sep 1 17:50:01 CEST 2010


I need to line up windows having titlebar with windows having no  
titlebar, and I need to do this under both MDI and SDI style  
applications. To account for the titlebar, I need the height of a  
standard window titlebar, so I use QStyle::pixelMetric().

On the Macintosh, I can see that the titlebar is 22 pixels high using  
the Apple developer's tool Pixie. But pixelMetric is telling me 26.  
Here's my code using pixelMetric():

QStyle * wStyle = style();
QStyleOptionTitleBar so;
so.titleBarState = 1;		// kThemeStateActive
so.titleBarFlags = Qt::Window;
	
int titleBarHeight = wStyle->pixelMetric(QStyle::PM_TitleBarHeight,  
&so, this);
int framewidth = wStyle- 
 >pixelMetric(QStyle::PM_MdiSubWindowFrameWidth , &so, this);

On a Macintosh titleBarHeight is coming back as 26.

I see in the code for QMacStyle::pixelMetric():

    case PM_TitleBarHeight:
        if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const  
QStyleOptionTitleBar *>(opt)) {
            HIThemeWindowDrawInfo wdi;
            wdi.version = qt_mac_hitheme_version;
            wdi.state = kThemeStateActive;
            wdi.windowType = QtWinType;
            if (tb->titleBarState)
                wdi.attributes = kThemeWindowHasFullZoom |  
kThemeWindowHasCloseBox
                                  | kThemeWindowHasCollapseBox;
            else if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
                wdi.attributes = kThemeWindowHasCloseBox;
            else
                wdi.attributes = 0;
            wdi.titleHeight = tb->rect.height();
            wdi.titleWidth = tb->rect.width();
            QCFType<HIShapeRef> region;
            HIRect hirect = qt_hirectForQRect(tb->rect);
            if (hirect.size.width <= 0)
                hirect.size.width = 100;
            if (hirect.size.height <= 0)
                hirect.size.height = 30;

            HIThemeGetWindowShape(&hirect, &wdi, kWindowTitleBarRgn,  
&region);
            HIRect rect;
            ptrHIShapeGetBounds(region, &rect);
            ret = int(rect.size.height);
            ret += 4;
        }
        break;

Note at the bottom where it adds 4 to the result!

Why?


Thanks for any insight.

Regards,
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax   (503) 620-6754
email   support at WaveMetrics.com

Regards, John Weeks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100901/243358b2/attachment.html 


More information about the Qt-interest-old mailing list