I've found the root cause
QSize QWidgetPrivate
::adjustedSize() const {
if (q->isWindow()) {
Qt::Orientations exp;
if (layout) {
if (layout->hasHeightForWidth())
s.setHeight(layout->totalHeightForWidth(s.width()));
exp = layout->expandingDirections();
} else
{
if (q->sizePolicy().hasHeightForWidth())
s.setHeight(q->heightForWidth(s.width()));
exp = q->sizePolicy().expandingDirections();
}
if (exp & Qt::Horizontal)
s.setWidth(qMax(s.width(), 200));
if (exp & Qt::Vertical)
s.setHeight(qMax(s.height(), 100));
#if defined(Q_WS_X11)
#else // all others
#endif
#if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
s.setWidth(qMin(s.width(), screen.width()));
s.setHeight(qMin(s.height(), screen.height()));
#else
s.setWidth(qMin(s.width(), screen.width()*2/3));
s.setHeight(qMin(s.height(), screen.height()*2/3));
#endif
if (QTLWExtra *extra = maybeTopData())
extra->sizeAdjusted = true;
}
if (!s.isValid()) {
QRect r
= q
->childrenRect
();
// get children rectangle if (r.isNull())
return s;
s
= r.
size() + QSize(2 * r.
x(),
2 * r.
y());
}
return s;
}
QSize QWidgetPrivate::adjustedSize() const
{
Q_Q(const QWidget);
QSize s = q->sizeHint();
if (q->isWindow()) {
Qt::Orientations exp;
if (layout) {
if (layout->hasHeightForWidth())
s.setHeight(layout->totalHeightForWidth(s.width()));
exp = layout->expandingDirections();
} else
{
if (q->sizePolicy().hasHeightForWidth())
s.setHeight(q->heightForWidth(s.width()));
exp = q->sizePolicy().expandingDirections();
}
if (exp & Qt::Horizontal)
s.setWidth(qMax(s.width(), 200));
if (exp & Qt::Vertical)
s.setHeight(qMax(s.height(), 100));
#if defined(Q_WS_X11)
QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen());
#else // all others
QRect screen = QApplication::desktop()->screenGeometry(q->pos());
#endif
#if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
s.setWidth(qMin(s.width(), screen.width()));
s.setHeight(qMin(s.height(), screen.height()));
#else
s.setWidth(qMin(s.width(), screen.width()*2/3));
s.setHeight(qMin(s.height(), screen.height()*2/3));
#endif
if (QTLWExtra *extra = maybeTopData())
extra->sizeAdjusted = true;
}
if (!s.isValid()) {
QRect r = q->childrenRect(); // get children rectangle
if (r.isNull())
return s;
s = r.size() + QSize(2 * r.x(), 2 * r.y());
}
return s;
}
To copy to clipboard, switch view to plain text mode
The root was that window has a default size policy, so adjustSize() never ran into using childrenRect to expand size. How could I avoid to it?
Added after 4 minutes:
Originally Posted by
Lykurg
You have to resize() your mainwindow, not the frame inside it. And calling adjustSize() destroy all other setting you made before.
but I can't get the total size of frame plus other bars (toolbar, menubar, etc).
Bookmarks