149QTipLabel::QTipLabel(
const QString &text,
const QPoint &pos, QWidget *w,
int msecDisplayTime)
150 : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget)
151#if QT_CONFIG(style_stylesheet)
152 , styleSheetParent(
nullptr)
158 setForegroundRole(QPalette::ToolTipText);
159 setBackgroundRole(QPalette::ToolTipBase);
160 setPalette(QToolTip::palette());
162 setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth,
nullptr,
this));
163 setFrameStyle(QFrame::NoFrame);
164 setAlignment(Qt::AlignLeft);
166 qApp->installEventFilter(
this);
167 setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity,
nullptr,
this) / 255.0);
168 setMouseTracking(
true);
170 reuseTip(text, msecDisplayTime, pos);
201 d_func()->setScreenForPoint(pos);
203 QFontMetrics fm(font());
206 if (fm.descent() == 2 && fm.ascent() >= 11)
208 setWordWrap(Qt::mightBeRichText(text()));
209 QSize sh = sizeHint();
210 const QScreen *screen = getTipScreen(pos,
this);
211 if (!wordWrap() && sh.width() > screen->geometry().width()) {
231 QStyleHintReturnMask frameMask;
233 option.initFrom(
this);
234 if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option,
this, &frameMask))
235 setMask(frameMask.region);
237 QLabel::resizeEvent(e);
293 case QEvent::KeyPress:
294 case QEvent::KeyRelease: {
295 const int key =
static_cast<QKeyEvent *>(e)->key();
297 if (key < Qt::Key_Shift || key > Qt::Key_ScrollLock)
298 hideTipImmediately();
307#if defined (Q_OS_QNX) || defined (Q_OS_WASM)
309 case QEvent::WindowActivate:
310 case QEvent::FocusIn:
312 case QEvent::WindowDeactivate:
315 hideTipImmediately();
317 case QEvent::FocusOut:
318 if (
reinterpret_cast<QWindow*>(o) != windowHandle())
320 hideTipImmediately();
323 case QEvent::WindowActivate:
324 case QEvent::WindowDeactivate:
325 case QEvent::FocusIn:
326 case QEvent::FocusOut:
328 case QEvent::MouseButtonPress:
329 case QEvent::MouseButtonRelease:
330 case QEvent::MouseButtonDblClick:
335 case QEvent::MouseMove:
336 if (o == widget && !rect.isNull() && !rect.contains(
static_cast<QMouseEvent*>(e)->position().toPoint()))
354#if QT_CONFIG(style_stylesheet)
355 if (testAttribute(Qt::WA_StyleSheet) || (w && qt_styleSheet(w->style()))) {
357 QTipLabel::instance->setProperty(
"_q_stylesheet_parent", QVariant::fromValue(w));
359 QTipLabel::instance->setStyleSheet(
"/* */"_L1);
362 QTipLabel::instance->styleSheetParent = w;
364 connect(w, &QWidget::destroyed,
365 QTipLabel::instance, &QTipLabel::styleSheetParentDestroyed);
371 QTipLabel::instance->updateSize(pos);
376 const QScreen *screen = getTipScreen(pos, w);
378 if (
const QPlatformScreen *platformScreen = screen ? screen->handle() :
nullptr) {
379 QPlatformCursor *cursor = platformScreen->cursor();
381 const QSize nativeSize = cursor ? cursor->size() : QSize(16, 16);
382 const QSize cursorSize = QHighDpi::fromNativePixels(nativeSize,
384 QPoint offset(2, cursorSize.height());
386 if (cursorSize.height() > 2 *
this->height())
387 offset =
QPoint(cursorSize.width() / 2, 0);
391#if QT_CONFIG(wayland)
393 if (
auto waylandWindow =
dynamic_cast<QNativeInterface::Private::QWaylandWindow*>(windowHandle()->handle())) {
396 const QRect controlGeometry(QRect(p.x() - 4, p.y() - 24, 4, 24));
397 waylandWindow->setParentControlGeometry(controlGeometry);
398 waylandWindow->setExtendedWindowType(QNativeInterface::Private::QWaylandWindow::ToolTip);
402 QRect screenRect = screen->geometry();
403 if (p.x() +
this->width() > screenRect.x() + screenRect.width())
404 p.rx() -= 4 +
this->width();
405 if (p.y() +
this->height() > screenRect.y() + screenRect.height())
406 p.ry() -= 24 +
this->height();
407 if (p.y() < screenRect.y())
408 p.setY(screenRect.y());
409 if (p.x() +
this->width() > screenRect.x() + screenRect.width())
410 p.setX(screenRect.x() + screenRect.width() -
this->width());
411 if (p.x() < screenRect.x())
412 p.setX(screenRect.x());
413 if (p.y() +
this->height() > screenRect.y() + screenRect.height())
414 p.setY(screenRect.y() + screenRect.height() -
this->height());
456void QToolTip::showText(
const QPoint &pos,
const QString &text, QWidget *w,
const QRect &rect,
int msecDisplayTime)
458 if (QTipLabel::instance && QTipLabel::instance->isVisible()) {
460 QTipLabel::instance->hideTip();
462 }
else if (!QTipLabel::instance->fadingOut) {
465 QPoint localPos = pos;
467 localPos = w->mapFromGlobal(pos);
468 if (QTipLabel::instance->tipChanged(localPos, text, w)){
469 QTipLabel::instance->reuseTip(text, msecDisplayTime, pos);
470 QTipLabel::instance->setTipRect(w, rect);
471 QTipLabel::instance->placeTip(pos, w);
477 if (!text.isEmpty()) {
478 QWidget *tipLabelParent = [w]() -> QWidget* {
488 new QTipLabel(text, pos, tipLabelParent, msecDisplayTime);
489 QWidgetPrivate::get(QTipLabel::instance)->setScreen(QTipLabel::getTipScreen(pos, w));
490 QTipLabel::instance->setTipRect(w, rect);
491 QTipLabel::instance->placeTip(pos, w);
492 QTipLabel::instance->setObjectName(
"qtooltip_label"_L1);
494#if QT_CONFIG(effects)
495 if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
496 qFadeEffect(QTipLabel::instance);
497 else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
498 qScrollEffect(QTipLabel::instance);
500 QTipLabel::instance->showNormal();
502 QTipLabel::instance->showNormal();