From 009abcd7b66738bece6cf354776dfb2ef401636b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 8 Nov 2019 11:03:14 +0100 Subject: QWidget: React to platform surface being created or destroyed The platform window may create or destroy its surface from other entry points than the QWidget API, in which case QWidget needs to sync up its own state to match. In particular WA_WState_Created and the winId needs to be recomputed. Fixes: QTBUG-69289 Fixes: QTBUG-77350 Change-Id: I769e58ead3c2efcf8c451c363108848feade9388 Reviewed-by: Volker Hilsheimer Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/widgets/kernel') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 5a0ea58cf8..dcc694efe4 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -8624,6 +8624,23 @@ bool QWidget::event(QEvent *event) } } switch (event->type()) { + case QEvent::PlatformSurface: { + // Sync up QWidget's view of whether or not the widget has been created + switch (static_cast(event)->surfaceEventType()) { + case QPlatformSurfaceEvent::SurfaceCreated: + if (!testAttribute(Qt::WA_WState_Created)) + create(); + break; + case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: + if (testAttribute(Qt::WA_WState_Created)) { + // Child windows have already been destroyed by QWindow, + // so we skip them here. + destroy(false, false); + } + break; + } + break; + } case QEvent::MouseMove: mouseMoveEvent((QMouseEvent*)event); break; -- cgit v1.2.3 From baed8534bc1dac36a9d0ef4240fc14398076a192 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 5 Nov 2019 14:06:46 +0100 Subject: Move the tooltip out of the way of very large mouse cursors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users that have large mouse pointers configured in their settings can not see tooltips, as they are obscured by the pointer. Native applications on Windows and macOS have the same problem, which includes the tooltips for the minimize/maximize/close controls in the window frame of e.g. Explorer. Introduce QPlatformCursor::size that returns a value that is based on the user's settings, or a default value. We can then use that value to move the tooltip out of the way. On Windows, the calculation of the cursor size is based on experimenting with the settings, which are in logical independent pixels. The placement of the tooltip attempts to keep existing behavior, and to not end up with a tooltip that's very far away from the tip of the arrow even for very large mouse cursors. [ChangeLog][QtWidgets][QToolTip] Make sure that the tooltip is not obscured by very large mouse pointers on Windows and macOS. Change-Id: I8e13b7a166bfe8b59cef4765c950f90fefeaef9d Fixes: QTBUG-79627 Reviewed-by: Friedemann Kleint Reviewed-by: Morten Johan Sørvig --- src/widgets/kernel/qtooltip.cpp | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/widgets/kernel') diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 97a279d65d..1ec3612457 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -53,11 +53,14 @@ #endif #include #include +#include +#include #include #ifndef QT_NO_TOOLTIP #include #include +#include #include QT_BEGIN_NAMESPACE @@ -398,24 +401,34 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w) } #endif //QT_NO_STYLE_STYLESHEET - - QRect screen = QDesktopWidgetPrivate::screenGeometry(getTipScreen(pos, w)); - QPoint p = pos; - p += QPoint(2, 16); - - if (p.x() + this->width() > screen.x() + screen.width()) + int screenNumber = getTipScreen(pos, w); + QScreen *screen = QGuiApplication::screens().at(screenNumber); + if (screen) { + const QPlatformScreen *platformScreen = screen->handle(); + const QSize cursorSize = QHighDpi::fromNativePixels(platformScreen->cursor()->size(), + platformScreen); + QPoint offset(2, cursorSize.height()); + // assuming an arrow shape, we can just move to the side for very large cursors + if (cursorSize.height() > 2 * this->height()) + offset = QPoint(cursorSize.width() / 2, 0); + + p += offset; + + QRect screenRect = screen->geometry(); + if (p.x() + this->width() > screenRect.x() + screenRect.width()) p.rx() -= 4 + this->width(); - if (p.y() + this->height() > screen.y() + screen.height()) + if (p.y() + this->height() > screenRect.y() + screenRect.height()) p.ry() -= 24 + this->height(); - if (p.y() < screen.y()) - p.setY(screen.y()); - if (p.x() + this->width() > screen.x() + screen.width()) - p.setX(screen.x() + screen.width() - this->width()); - if (p.x() < screen.x()) - p.setX(screen.x()); - if (p.y() + this->height() > screen.y() + screen.height()) - p.setY(screen.y() + screen.height() - this->height()); + if (p.y() < screenRect.y()) + p.setY(screenRect.y()); + if (p.x() + this->width() > screenRect.x() + screenRect.width()) + p.setX(screenRect.x() + screenRect.width() - this->width()); + if (p.x() < screenRect.x()) + p.setX(screenRect.x()); + if (p.y() + this->height() > screenRect.y() + screenRect.height()) + p.setY(screenRect.y() + screenRect.height() - this->height()); + } this->move(p); } -- cgit v1.2.3