diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2012-12-10 14:48:19 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-24 20:41:05 +0100 |
commit | 153d613353863987322db81f3c31e33541ef7226 (patch) | |
tree | ad2e8a3793641bc10cc8bbae2d0adefb70025b53 /src/widgets | |
parent | d9ff510f02bba63dabe7a081a68296056a89ae4c (diff) |
Transient QWindows centered; default-constructed geometry
Default-constructed geometry does not mean put the window at 0,0,
and it does not mean center the window on the screen: it means
let the window manager position the window. If the window is
explicitly positioned at 0,0 though, that is a higher priority
than the transient hint; without this change, the transientFor property
had no effect. On X11, transient means use center "gravity" to
make the transient window exactly centered. But the user can still
override the geometry of a transient window, as with any window.
On OSX and Windows, neither transient window functionality nor smart
initial positioning are provided, so a window with no position set
will be centered on the screen, and a transient window will be put
at the center of its transientParent.
Change-Id: I4f5e37480eef5d105e45ffd60362a57f13ec55f5
Task-number: QTBUG-26903
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qwidget_qpa.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 84693d02a5..2ffe9c5de5 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -109,7 +109,10 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO win->setFlags(data.window_flags); fixPosIncludesFrame(); - win->setGeometry(q->geometry()); + if (q->testAttribute(Qt::WA_Moved)) + win->setGeometry(q->geometry()); + else + win->resize(q->size()); win->setScreen(QGuiApplication::screens().value(topData()->screenIndex, 0)); if (q->testAttribute(Qt::WA_TranslucentBackground)) { @@ -466,19 +469,6 @@ void QWidget::activateWindow() wnd->requestActivate(); } -// Position top level windows at the center, avoid showing -// Windows at the default 0,0 position excluding the frame. -static inline QRect positionTopLevelWindow(QRect geometry, const QScreen *screen) -{ - if (screen && geometry.x() == 0 && geometry.y() == 0) { - const QRect availableGeometry = screen->availableGeometry(); - if (availableGeometry.width() > geometry.width() - && availableGeometry.height() > geometry.height()) - geometry.moveCenter(availableGeometry.center()); - } - return geometry; -} - // move() was invoked with Qt::WA_WState_Created not set (frame geometry // unknown), that is, crect has a position including the frame. // If we can determine the frame strut, fix that and clear the flag. @@ -529,16 +519,16 @@ void QWidgetPrivate::show_sys() if (q->isWindow()) fixPosIncludesFrame(); QRect geomRect = q->geometry(); - if (q->isWindow()) { - if (!q->testAttribute(Qt::WA_Moved)) - geomRect = positionTopLevelWindow(geomRect, window->screen()); - } else { + if (!q->isWindow()) { QPoint topLeftOfWindow = q->mapTo(q->nativeParentWidget(),QPoint()); geomRect.moveTopLeft(topLeftOfWindow); } const QRect windowRect = window->geometry(); if (windowRect != geomRect) { - window->setGeometry(geomRect); + if (q->testAttribute(Qt::WA_Moved)) + window->setGeometry(geomRect); + else + window->resize(geomRect.size()); } if (QBackingStore *store = q->backingStore()) { |