summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qtooltip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/kernel/qtooltip.cpp')
-rw-r--r--src/widgets/kernel/qtooltip.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp
index 97a279d65d..33dd3e59b6 100644
--- a/src/widgets/kernel/qtooltip.cpp
+++ b/src/widgets/kernel/qtooltip.cpp
@@ -53,11 +53,14 @@
#endif
#include <qtextdocument.h>
#include <qdebug.h>
+#include <qpa/qplatformscreen.h>
+#include <qpa/qplatformcursor.h>
#include <private/qstylesheetstyle_p.h>
#ifndef QT_NO_TOOLTIP
#include <qlabel.h>
#include <QtWidgets/private/qlabel_p.h>
+#include <QtGui/private/qhighdpiscaling_p.h>
#include <qtooltip.h>
QT_BEGIN_NAMESPACE
@@ -151,7 +154,7 @@ public slots:
*/
void styleSheetParentDestroyed() {
setProperty("_q_stylesheet_parent", QVariant());
- styleSheetParent = 0;
+ styleSheetParent = nullptr;
}
private:
@@ -163,11 +166,11 @@ private:
QRect rect;
};
-QTipLabel *QTipLabel::instance = 0;
+QTipLabel *QTipLabel::instance = nullptr;
QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int msecDisplayTime)
#ifndef QT_NO_STYLE_STYLESHEET
- : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), styleSheetParent(0), widget(0)
+ : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), styleSheetParent(nullptr), widget(nullptr)
#else
: QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget), widget(0)
#endif
@@ -178,12 +181,12 @@ QTipLabel::QTipLabel(const QString &text, const QPoint &pos, QWidget *w, int mse
setBackgroundRole(QPalette::ToolTipBase);
setPalette(QToolTip::palette());
ensurePolished();
- setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
+ setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, nullptr, this));
setFrameStyle(QFrame::NoFrame);
setAlignment(Qt::AlignLeft);
setIndent(1);
qApp->installEventFilter(this);
- setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, 0, this) / 255.0);
+ setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity, nullptr, this) / 255.0);
setMouseTracking(true);
fadingOut = false;
reuseTip(text, msecDisplayTime, pos);
@@ -204,7 +207,7 @@ void QTipLabel::reuseTip(const QString &text, int msecDisplayTime, const QPoint
if (styleSheetParent){
disconnect(styleSheetParent, SIGNAL(destroyed()),
QTipLabel::instance, SLOT(styleSheetParentDestroyed()));
- styleSheetParent = 0;
+ styleSheetParent = nullptr;
}
#endif
@@ -278,7 +281,7 @@ void QTipLabel::mouseMoveEvent(QMouseEvent *e)
QTipLabel::~QTipLabel()
{
- instance = 0;
+ instance = nullptr;
}
void QTipLabel::hideTip()
@@ -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);
}
@@ -547,7 +560,7 @@ void QToolTip::showText(const QPoint &pos, const QString &text, QWidget *w)
*/
bool QToolTip::isVisible()
{
- return (QTipLabel::instance != 0 && QTipLabel::instance->isVisible());
+ return (QTipLabel::instance != nullptr && QTipLabel::instance->isVisible());
}
/*!