[Interest] QMdiSubWindow resize() does include the frame
Immanuel Weber
immanuel.weber at gmail.com
Wed Apr 24 21:28:10 CEST 2013
Thanks John for the code. It works fine. I'm not really into the qt internals, I don't know if it is enough to overload in QMdiSubWindow size() and resize() to account for your code snippets. Should this be reported as a bug?
Am Mittwoch, 24. April 2013 um 17:49 schrieb John Weeks:
> OK- this time I got the correct message sent to the correct address. Sorry about that whole series of mistakes. I gotta say, I really disagree with the general notion that putting the list as the Reply To: is a bad thing...
>
>
>
>
> Yep- I got caught by this one, too. The explanation is that a QMdiSubWindow isn't actually a window, it's a child widget of the QMdiArea that contains it. Consequently, what looks like a window title bar is actually a child widget drawn by Qt. As such, the whole "window" is the QMdiSubWindow.
>
> That doesn't really help, does it?
>
> Here's my code to get the titlebar height in order to correct it:
>
> ----------------------------
> if ( (myWidget()->windowFlags() & Qt::FramelessWindowHint) != 0)
> return 0;
>
> QStyle * wStyle = myWidget()->style();
> QStyleOptionTitleBar so;
> so.titleBarState = 1; // kThemeStateActive
> so.titleBarFlags = Qt::Window;
>
> // it seems that pixelMetric includes the frame in the titlebar height.
> int titleBarHeight = wStyle->pixelMetric(QStyle::PM_TitleBarHeight, &so, myWidget());
> #ifdef MACIGOR
> titleBarHeight -= 4; // pixelMetric adds 4 pixels for some unknown reason.
> #endif
>
> return titleBarHeight;
> ----------------------------
>
>
> You will also need the frame width:
>
> ----------------------------
> if ( (myWidget()->windowFlags() & Qt::FramelessWindowHint) != 0)
> return 0;
>
> QStyle * wStyle = myWidget()->style();
> QStyleOptionTitleBar so;
> so.titleBarState = 1; // kThemeStateActive
> so.titleBarFlags = Qt::Window;
>
> return wStyle->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth , &so, myWidget());
> ----------------------------
>
>
> If anyone sees a problem with this, I'd be interested in hearing about it. So far it seems to work, at least on Macintosh and Windows.
>
> -John Weeks
>
>
> On 23-Apr-2013, at 1:22 PM, Immanuel Weber wrote:
> > Hi all,
> >
> > I'm trying to set the inner area of a QMdiSubArea to a specific size, but the the resize(..) member of QMdiSubArea includes the frame. As stated in the documentation (http://qt-project.org/doc/qt-5.0/qtwidgets/application-windows.html#window-geometry) resize(..) (belonging to size()) should exclude the frame and set the size of the inner area, but it sets the size of the complete sub window. Matching that, size() returns the same frame-including-value as frameSize() does. I know that there are (non-beautiful/simple) ways to do that, by determining the border width of a sub window, but I'm just curious why we have such an inconsitency here.
> > I add a minimal example, where you can see the normal behavior and the one of the sub window.
> > In addition there is a commented resize command, which produces (uncommented) on my machines another strange behavior: the window is moved to the top left corner of the screen, so that the header bar of the window lies outside of it.
> >
> > #include <QApplication>
> > #include <QtWidgets/QtWidgets>
> > #include <QDebug>
> >
> >
> > int main(int argc, char *argv[])
> > {
> > QApplication a(argc, argv);
> > QPushButton * button = new QPushButton("button");
> > QMdiArea area;
> > QMdiSubWindow * sub = area.addSubWindow(button);
> > area.show();
> > qDebug() << "strange: "<< sub->size() << sub->frameSize();
> > qDebug() << "expected: " << area.size() << area.frameSize();
> >
> > // area.resize(500, 500);
> >
> > return a.exec();
> > }
> >
> > (all on Win7 x64 with a Qt 5.0.1/.2 x86 MSVC release)
> >
> > Any ideas on that?
> > Greetings
> > Immanuel
> >
> >
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org (mailto:Interest at qt-project.org)
> > http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org (mailto:Interest at qt-project.org)
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130424/59ce2682/attachment.html>
More information about the Interest
mailing list