From be22e8fa95f5bbb0b9faf0b1d75d943c8524536e Mon Sep 17 00:00:00 2001 From: Jay Nabonne Date: Wed, 12 Jun 2019 10:27:42 +0100 Subject: [PATCH] Fix DoMoveWindow() to take into account the frame extent Using "move" is correct for positioning, as it takes into account the frame extent. Unfortunately, there is no corresponding API to set the frame size. So we need to compute the effective client size and use "resize". We can't use "setGeometry" for this purpose, since a widget's "geometry" excludes the frame size. We would need to adjust the position to go from frame to client coordinates. It's more straightforward to simply have Qt do it with "move". Closes https://github.com/wxWidgets/wxWidgets/pull/1349 --- src/qt/window.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/qt/window.cpp b/src/qt/window.cpp index 4410308d7e..93d72d8ff8 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -977,9 +977,19 @@ void wxWindowQt::DoMoveWindow(int x, int y, int width, int height) QWidget *qtWidget = GetHandle(); qtWidget->move( x, y ); - qtWidget->resize( width, height ); -} + // There doesn't seem to be any way to change Qt frame size directly, so + // change the widget size, but take into account the extra margins + // corresponding to the frame decorations. + const QSize frameSize = qtWidget->frameSize(); + const QSize innerSize = qtWidget->geometry().size(); + const QSize frameSizeDiff = frameSize - innerSize; + + const int clientWidth = std::max(width - frameSizeDiff.width(), 0); + const int clientHeight = std::max(height - frameSizeDiff.height(), 0); + + qtWidget->resize(clientWidth, clientHeight); +} #if wxUSE_TOOLTIPS void wxWindowQt::QtApplyToolTip(const wxString& text)