Skip to content

Commit

Permalink
QWindow: bail out early on resize() if size has not changed
Browse files Browse the repository at this point in the history
On some platforms, like Windows and Linux, calling resize() may
unexpectedly reset window state even when the actual size has not
changed. So, bail out early on QWindow::resize() if new size is the
same.

Task-number: QTBUG-115699
Change-Id: I64ad611044008964b5201951a50f3866e2108b49
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
  • Loading branch information
VladimirBelyavsky committed Sep 15, 2023
1 parent 9c0def8 commit b0ba5c7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/gui/kernel/qwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,7 @@ void QWindowPrivate::setMinOrMaxSize(QSize *oldSizeMember, const QSize &size,
|| minimumSize.height() <= maximumSize.height()) {
const QSize currentSize = q->size();
const QSize boundedSize = currentSize.expandedTo(minimumSize).boundedTo(maximumSize);
if (currentSize != boundedSize)
q->resize(boundedSize);
q->resize(boundedSize);
}
}

Expand Down Expand Up @@ -1646,20 +1645,18 @@ void QWindow::setY(int arg)
\property QWindow::width
\brief the width of the window's geometry
*/
void QWindow::setWidth(int arg)
void QWindow::setWidth(int w)
{
if (width() != arg)
resize(arg, height());
resize(w, height());
}

/*!
\property QWindow::height
\brief the height of the window's geometry
*/
void QWindow::setHeight(int arg)
void QWindow::setHeight(int h)
{
if (height() != arg)
resize(width(), arg);
resize(width(), h);
}

/*!
Expand Down Expand Up @@ -1981,12 +1978,16 @@ void QWindow::resize(int w, int h)
void QWindow::resize(const QSize &newSize)
{
Q_D(QWindow);

const QSize oldSize = size();
if (newSize == oldSize)
return;

d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
if (d->platformWindow) {
d->platformWindow->setGeometry(
QHighDpi::toNativeWindowGeometry(QRect(position(), newSize), this));
} else {
const QSize oldSize = d->geometry.size();
d->geometry.setSize(newSize);
if (newSize.width() != oldSize.width())
emit widthChanged(newSize.width());
Expand Down

0 comments on commit b0ba5c7

Please sign in to comment.