QMainWindow: respect the maximum size of the central widget
Make sure the dock widgets get the available space when the central widget cannot expand any more. [ChangeLog][QtWidgets][QMainWindow] Dock widgets will now be resized properly when the central widget has a fixed size. Task-number: QTBUG-40410 Change-Id: Id06c07b79aa3102aa41212fa2c621f5fa426fe02 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
parent
77339e6bbf
commit
2bfee10f3a
@ -2575,12 +2575,14 @@ void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,
|
||||
{
|
||||
QSize center_hint(0, 0);
|
||||
QSize center_min(0, 0);
|
||||
QSize center_max(0, 0);
|
||||
const bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty();
|
||||
if (have_central) {
|
||||
center_hint = centralWidgetRect.size();
|
||||
if (!center_hint.isValid())
|
||||
center_hint = centralWidgetItem->sizeHint();
|
||||
center_min = centralWidgetItem->minimumSize();
|
||||
center_max = centralWidgetItem->maximumSize();
|
||||
}
|
||||
|
||||
QRect center_rect = rect;
|
||||
@ -2656,7 +2658,7 @@ void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,
|
||||
left = (tl_significant && bl_significant) ? left_min.height() : 0;
|
||||
right = (tr_significant && br_significant) ? right_min.height() : 0;
|
||||
ver_struct_list[1].minimumSize = qMax(left, center_min.height(), right);
|
||||
ver_struct_list[1].maximumSize = have_central ? QWIDGETSIZE_MAX : 0;
|
||||
ver_struct_list[1].maximumSize = center_max.height();
|
||||
ver_struct_list[1].expansive = have_central;
|
||||
ver_struct_list[1].empty = docks[QInternal::LeftDock].isEmpty()
|
||||
&& !have_central
|
||||
@ -2717,7 +2719,7 @@ void QDockAreaLayout::getGrid(QVector<QLayoutStruct> *_ver_struct_list,
|
||||
bottom = (bl_significant && br_significant) ? bottom_min.width() : 0;
|
||||
hor_struct_list[1].minimumSize = qMax(top, center_min.width(), bottom);
|
||||
|
||||
hor_struct_list[1].maximumSize = have_central ? QWIDGETSIZE_MAX : 0;
|
||||
hor_struct_list[1].maximumSize = center_max.width();
|
||||
hor_struct_list[1].expansive = have_central;
|
||||
hor_struct_list[1].empty = !have_central;
|
||||
hor_struct_list[1].pos = center_rect.left();
|
||||
|
@ -137,6 +137,7 @@ private slots:
|
||||
#endif
|
||||
void addToolbarAfterShow();
|
||||
void centralWidgetSize();
|
||||
void fixedSizeCentralWidget();
|
||||
void dockWidgetSize();
|
||||
void QTBUG2774_stylechange();
|
||||
void QTBUG15080_restoreState();
|
||||
@ -1737,6 +1738,50 @@ void tst_QMainWindow::centralWidgetSize()
|
||||
QTRY_COMPARE(widget.size(), widget.sizeHint());
|
||||
}
|
||||
|
||||
void tst_QMainWindow::fixedSizeCentralWidget()
|
||||
{
|
||||
// QTBUG-40410: dock widgets does not get all the available space when
|
||||
// central widget is fixed size
|
||||
QMainWindow mainWindow;
|
||||
mainWindow.setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
|
||||
|
||||
MyWidget widget;
|
||||
widget.setFixedSize(100,100);
|
||||
mainWindow.setCentralWidget(&widget);
|
||||
|
||||
QDockWidget dock("D1");
|
||||
QWidget *child = new MyWidget;
|
||||
dock.setWidget(child);
|
||||
mainWindow.addDockWidget(Qt::TopDockWidgetArea, &dock);
|
||||
|
||||
QDockWidget dock2("D2");
|
||||
dock2.setWidget(new MyWidget);
|
||||
mainWindow.addDockWidget(Qt::LeftDockWidgetArea, &dock2);
|
||||
|
||||
QSize sizeH = mainWindow.sizeHint();
|
||||
QSize mwSize = QSize(sizeH.width(), sizeH.height() * 2);
|
||||
mainWindow.resize(mwSize);
|
||||
mainWindow.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&mainWindow));
|
||||
if (mainWindow.height() < mwSize.height())
|
||||
QSKIP("The screen is too small for this test");
|
||||
|
||||
// first, check that we get more than the size hint when we have more space
|
||||
QTRY_VERIFY(child->height() > child->sizeHint().height());
|
||||
int childHeight = child->height();
|
||||
|
||||
if (qGuiApp->styleHints()->showIsFullScreen())
|
||||
QSKIP("The platform is auto maximizing, so we cannot resize the window");
|
||||
|
||||
// then, check that we get nothing when there is no space
|
||||
mainWindow.resize(100,100);
|
||||
QTRY_COMPARE(child->height(), 0);
|
||||
|
||||
// finally verify that we get the space back when we resize to the old size
|
||||
mainWindow.resize(mwSize);
|
||||
QTRY_COMPARE(child->height(), childHeight);
|
||||
}
|
||||
|
||||
void tst_QMainWindow::dockWidgetSize()
|
||||
{
|
||||
QMainWindow mainWindow;
|
||||
|
Loading…
Reference in New Issue
Block a user