Implement QWindowContainer::minimumSizeHint()
It will return the minimumSize of the underlying QWindow. The container can then be put inside QLayouts without risking to be shrunk to a smaller size than the QWindow::minimumSize. Whenever the QWindow::minimumWidth or QWindow::minimumHeight changes, we call QWindowContainer::updateGeometry(), which will make the layout re-query QWindowContainer::minimumSizeHint() again. Task-number: QTBUG-121798 Change-Id: Ib7ece7d9d75f2e4964ca9042d8d8b95ce3b17739 Reviewed-by: Doris Verria <doris.verria@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>bb10
parent
7d44817fc0
commit
ddc80cc63d
|
|
@ -221,6 +221,9 @@ QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt:
|
|||
|
||||
connect(qGuiApp, &QGuiApplication::focusWindowChanged,
|
||||
this, &QWindowContainer::focusWindowChanged);
|
||||
|
||||
connect(containedWindow(), &QWindow::minimumHeightChanged, this, &QWindowContainer::updateGeometry);
|
||||
connect(containedWindow(), &QWindow::minimumWidthChanged, this, &QWindowContainer::updateGeometry);
|
||||
}
|
||||
|
||||
QWindow *QWindowContainer::containedWindow() const
|
||||
|
|
@ -373,6 +376,11 @@ bool QWindowContainer::event(QEvent *e)
|
|||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
QSize QWindowContainer::minimumSizeHint() const
|
||||
{
|
||||
return containedWindow() ? containedWindow()->minimumSize() : QSize(0, 0);
|
||||
}
|
||||
|
||||
typedef void (*qwindowcontainer_traverse_callback)(QWidget *parent);
|
||||
static void qwindowcontainer_traverse(QWidget *parent, qwindowcontainer_traverse_callback callback)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public:
|
|||
explicit QWindowContainer(QWindow *embeddedWindow, QWidget *parent = nullptr, Qt::WindowFlags f = { });
|
||||
~QWindowContainer();
|
||||
QWindow *containedWindow() const;
|
||||
QSize minimumSizeHint() const override;
|
||||
|
||||
static void toplevelAboutToBeDestroyed(QWidget *parent);
|
||||
static void parentWasChanged(QWidget *parent);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <qscreen.h>
|
||||
#include <qscopedpointer.h>
|
||||
#include <qevent.h>
|
||||
#include <qboxlayout.h>
|
||||
|
||||
|
||||
class Window : public QWindow
|
||||
|
|
@ -46,6 +47,7 @@ public:
|
|||
private slots:
|
||||
void testShow();
|
||||
void testPositionAndSize();
|
||||
void testSizeHints();
|
||||
void testExposeObscure();
|
||||
void testOwnership();
|
||||
void testBehindTheScenesDeletion();
|
||||
|
|
@ -109,7 +111,29 @@ void tst_QWindowContainer::testPositionAndSize()
|
|||
QCOMPARE(window->height(), container->height());
|
||||
}
|
||||
|
||||
void tst_QWindowContainer::testSizeHints()
|
||||
{
|
||||
QScopedPointer<QWidget> tlw(new QWidget);
|
||||
QWindow *window = new QWindow();
|
||||
window->setMinimumSize(QSize(200, 200));
|
||||
window->setGeometry(m_availableGeometry.x() + 300, m_availableGeometry.y() + 400, 500, 600);
|
||||
|
||||
QScopedPointer<QWidget> container(QWidget::createWindowContainer(window));
|
||||
container->setWindowTitle(QTest::currentTestFunction());
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout(tlw.data());
|
||||
vbox->addWidget(container.data());
|
||||
vbox->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Size hints should work regardless of visibility
|
||||
QCOMPARE(container->minimumSizeHint(), window->minimumSize());
|
||||
QCOMPARE(vbox->minimumSize(), window->minimumSize());
|
||||
|
||||
// Respect dynamic updates
|
||||
window->setMinimumSize(QSize(210, 210));
|
||||
QCOMPARE(container->minimumSizeHint(), window->minimumSize());
|
||||
QCOMPARE(vbox->minimumSize(), window->minimumSize());
|
||||
}
|
||||
|
||||
void tst_QWindowContainer::testExposeObscure()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue