diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-11-02 12:45:11 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-03 09:43:11 +0000 |
commit | b803bf485bdd35370e3420e990acfbe8e3bf5038 (patch) | |
tree | 81b54dda723d286fd58b75788bf59ad2a431babf | |
parent | c9ceed0d8fdf6b4a77c08712b6cc9119d27aea48 (diff) | |
download | qtmultimedia-b803bf485bdd35370e3420e990acfbe8e3bf5038.tar.gz |
Fix QVideoWidget::setFullScreen()
setFullScreen(true) would always cause the video widget to be shown
on the primary screen instead of the current screen the app is being
shown on.
The reason for this is that setting the Qt::Window flag on the widget
will cause its position to be interpreted as relative to the screen
instead of its parent. This position is usually on the first screen,
so showFullScreen() will show it there.
Fix this by moving the video widget to the physical position on the
screen that it had inside its widget hierarchy before calling
showFullScreen(). Also restore that position on setFullScreen(false),
so that its position is correctly restored even without layouts.
Fixes: QTBUG-97895
Change-Id: I5207afb276e9369938d1c3d8814d9878367c6895
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit d6cef755f6874190d144d4d574c3c0d78f38dec4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/multimediawidgets/qvideowidget.cpp | 8 | ||||
-rw-r--r-- | src/multimediawidgets/qvideowidget_p.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/multimediawidgets/qvideowidget.cpp b/src/multimediawidgets/qvideowidget.cpp index b3331be09..511489dd9 100644 --- a/src/multimediawidgets/qvideowidget.cpp +++ b/src/multimediawidgets/qvideowidget.cpp @@ -146,10 +146,16 @@ void QVideoWidget::setFullScreen(bool fullScreen) Qt::WindowFlags flags = windowFlags(); if (fullScreen) { + // get the position of the widget in global coordinates + QPoint position = mapToGlobal(QPoint(0,0)); d->nonFullScreenFlags = flags & (Qt::Window | Qt::SubWindow); + d_ptr->nonFullscreenPos = pos(); flags |= Qt::Window; flags &= ~Qt::SubWindow; setWindowFlags(flags); + // move the widget to the position it had on screen, so that showFullScreen() will + // place it on the correct screen + move(position); showFullScreen(); } else { @@ -158,6 +164,8 @@ void QVideoWidget::setFullScreen(bool fullScreen) setWindowFlags(flags); showNormal(); + move(d_ptr->nonFullscreenPos); + d_ptr->nonFullscreenPos = {}; } d->wasFullScreen = fullScreen; } diff --git a/src/multimediawidgets/qvideowidget_p.h b/src/multimediawidgets/qvideowidget_p.h index 4b75a4c84..9a79f58ed 100644 --- a/src/multimediawidgets/qvideowidget_p.h +++ b/src/multimediawidgets/qvideowidget_p.h @@ -71,6 +71,7 @@ public: QVideoWindow *videoWindow = nullptr; QWidget *windowContainer = nullptr; + QPoint nonFullscreenPos; bool createBackend(); }; |