summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-08-12 13:21:42 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-08-17 15:08:39 +0200
commitc54a5b83804c00474d141b485b752a7c54169ebf (patch)
tree9016e1579b219072547a4d6892f500929e01e3c8 /src/widgets/kernel/qwidget.cpp
parentc4366ff0183a9a4a5c6eff0312b713e9c5eb97ea (diff)
Introduce QWidget::setScreen
Follows the QWindow semantics, and is a replacement for creating a QWidget with a QDesktopScreenWidget as the parent. We can now remove much of the special handling of QDesktopWidget and the Qt::Desktop window type, and get rid of QDesktopScreenWidget. Add a manual test that allows local testing. Our CI environments only have a single screen, and no multi-head display server setup which is the primary case where QWidget::setScreen is interesting. For the more common case of a virtual desktop, QWidget::setScreen has no real impact (just as QWindow::setScreen doesn't). Change-Id: Id0099e069d316741bacd8c795c396ccad37be297 Fixes: QTBUG-85483 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 2bfb4c3096..38f51e270e 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -42,7 +42,6 @@
#include "qapplication_p.h"
#include "qbrush.h"
#include "qcursor.h"
-#include "qdesktopwidget_p.h"
#include "qevent.h"
#include "qlayout.h"
#if QT_CONFIG(menu)
@@ -990,13 +989,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
if (allWidgets)
allWidgets->insert(q);
- QScreen *targetScreen = nullptr;
- if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
- const QDesktopScreenWidget *sw = qobject_cast<const QDesktopScreenWidget *>(parentWidget);
- targetScreen = sw ? sw->screen() : nullptr;
- parentWidget = nullptr;
- }
-
q->data = &data;
#if QT_CONFIG(thread)
@@ -1006,12 +998,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
}
#endif
- if (targetScreen) {
- topData()->initialScreen = targetScreen;
- if (QWindow *window = q->windowHandle())
- window->setScreen(targetScreen);
- }
-
data.fstrut_dirty = true;
data.winid = 0;
@@ -2424,8 +2410,7 @@ bool QWidgetPrivate::setScreen(QScreen *screen)
return false;
const QScreen *currentScreen = windowHandle() ? windowHandle()->screen() : nullptr;
if (currentScreen != screen) {
- if (!windowHandle()) // Try to create a window handle if not created.
- createWinId();
+ topData()->initialScreen = screen;
if (windowHandle())
windowHandle()->setScreen(screen);
return true;
@@ -2514,6 +2499,24 @@ QScreen *QWidget::screen() const
return QGuiApplication::primaryScreen();
}
+/*!
+ Sets the screen on which the widget should be shown to \a screen.
+
+ Setting the screen only makes sense for windows. If necessary, the widget's
+ window will get recreated on \a screen.
+
+ \note If the screen is part of a virtual desktop of multiple screens,
+ the window will not move automatically to \a newScreen. To place the
+ window relative to the screen, use the screen's topLeft() position.
+
+ \sa QWindow::setScreen
+*/
+void QWidget::setScreen(QScreen *screen)
+{
+ Q_D(QWidget);
+ d->setScreen(screen);
+}
+
#ifndef QT_NO_STYLE_STYLESHEET
/*!
@@ -10508,8 +10511,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
if (newparent && newparent->windowType() == Qt::Desktop) {
// make sure the widget is created on the same screen as the
// programmer specified desktop widget
- const QDesktopScreenWidget *sw = qobject_cast<const QDesktopScreenWidget *>(newparent);
- targetScreen = sw ? sw->screen() : nullptr;
+ targetScreen = newparent->screen();
newparent = nullptr;
}
@@ -10539,10 +10541,8 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
if (!newparent) {
f |= Qt::Window;
- if (!targetScreen) {
- if (parent)
- targetScreen = q->parentWidget()->window()->screen();
- }
+ if (parent)
+ targetScreen = q->parentWidget()->window()->screen();
}
bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);