Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-13475

QMacStyle::pixelMetric with QStyle::PM_TitleBarHeight gives bad result

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • Some future release
    • 4.6.3
    • None
    • OS X 10.5.8, Qt 4.6.3, Intel dual Quad-core Mac Pro.

    • macOS

    Description

      I need to line up windows having titlebar with windows having no titlebar. To account for the titlebar, I need the height of a standard window titlebar, so I use QStyle::pixelMetric().

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

      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?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            johnweeks John Weeks
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes