147QTipLabel::QTipLabel(
const QString &text,
const QPoint &pos, QWidget *w,
int msecDisplayTime)
148 : QLabel(w, Qt::ToolTip | Qt::BypassGraphicsProxyWidget)
149#if QT_CONFIG(style_stylesheet)
150 , styleSheetParent(
nullptr)
156 setForegroundRole(QPalette::ToolTipText);
157 setBackgroundRole(QPalette::ToolTipBase);
158 setPalette(QToolTip::palette());
160 setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth,
nullptr,
this));
161 setFrameStyle(QFrame::NoFrame);
162 setAlignment(Qt::AlignLeft);
164 qApp->installEventFilter(
this);
165 setWindowOpacity(style()->styleHint(QStyle::SH_ToolTipLabel_Opacity,
nullptr,
this) / 255.0);
166 setMouseTracking(
true);
168 reuseTip(text, msecDisplayTime, pos);
199 d_func()->setScreenForPoint(pos);
201 QFontMetrics fm(font());
204 if (fm.descent() == 2 && fm.ascent() >= 11)
206 setWordWrap(Qt::mightBeRichText(text()));
207 QSize sh = sizeHint();
208 const QScreen *screen = getTipScreen(pos,
this);
209 if (!wordWrap() && sh.width() > screen->geometry().width()) {
229 QStyleHintReturnMask frameMask;
231 option.initFrom(
this);
232 if (style()->styleHint(QStyle::SH_ToolTip_Mask, &option,
this, &frameMask))
233 setMask(frameMask.region);
235 QLabel::resizeEvent(e);
291 case QEvent::KeyPress:
292 case QEvent::KeyRelease: {
293 const int key =
static_cast<QKeyEvent *>(e)->key();
295 if (key < Qt::Key_Shift || key > Qt::Key_ScrollLock)
296 hideTipImmediately();
305#if defined (Q_OS_QNX) || defined (Q_OS_WASM)
307 case QEvent::WindowActivate:
308 case QEvent::FocusIn:
310 case QEvent::WindowDeactivate:
313 hideTipImmediately();
315 case QEvent::FocusOut:
316 if (
reinterpret_cast<QWindow*>(o) != windowHandle())
318 hideTipImmediately();
321 case QEvent::WindowActivate:
322 case QEvent::WindowDeactivate:
323 case QEvent::FocusIn:
324 case QEvent::FocusOut:
326 case QEvent::MouseButtonPress:
327 case QEvent::MouseButtonRelease:
328 case QEvent::MouseButtonDblClick:
333 case QEvent::MouseMove:
334 if (o == widget && !rect.isNull() && !rect.contains(
static_cast<QMouseEvent*>(e)->position().toPoint()))
352#if QT_CONFIG(style_stylesheet)
353 if (testAttribute(Qt::WA_StyleSheet) || (w && qt_styleSheet(w->style()))) {
355 QTipLabel::instance->setProperty(
"_q_stylesheet_parent", QVariant::fromValue(w));
357 QTipLabel::instance->setStyleSheet(
"/* */"_L1);
360 QTipLabel::instance->styleSheetParent = w;
362 connect(w, &QWidget::destroyed,
363 QTipLabel::instance, &QTipLabel::styleSheetParentDestroyed);
369 QTipLabel::instance->updateSize(pos);
374 const QScreen *screen = getTipScreen(pos, w);
376 if (
const QPlatformScreen *platformScreen = screen ? screen->handle() :
nullptr) {
377 QPlatformCursor *cursor = platformScreen->cursor();
379 const QSize nativeSize = cursor ? cursor->size() : QSize(16, 16);
380 const QSize cursorSize = QHighDpi::fromNativePixels(nativeSize,
382 QPoint offset(2, cursorSize.height());
384 if (cursorSize.height() > 2 *
this->height())
385 offset =
QPoint(cursorSize.width() / 2, 0);
389 QRect screenRect = screen->geometry();
390 if (p.x() +
this->width() > screenRect.x() + screenRect.width())
391 p.rx() -= 4 +
this->width();
392 if (p.y() +
this->height() > screenRect.y() + screenRect.height())
393 p.ry() -= 24 +
this->height();
394 if (p.y() < screenRect.y())
395 p.setY(screenRect.y());
396 if (p.x() +
this->width() > screenRect.x() + screenRect.width())
397 p.setX(screenRect.x() + screenRect.width() -
this->width());
398 if (p.x() < screenRect.x())
399 p.setX(screenRect.x());
400 if (p.y() +
this->height() > screenRect.y() + screenRect.height())
401 p.setY(screenRect.y() + screenRect.height() -
this->height());
443void QToolTip::showText(
const QPoint &pos,
const QString &text, QWidget *w,
const QRect &rect,
int msecDisplayTime)
445 if (QTipLabel::instance && QTipLabel::instance->isVisible()) {
447 QTipLabel::instance->hideTip();
449 }
else if (!QTipLabel::instance->fadingOut) {
452 QPoint localPos = pos;
454 localPos = w->mapFromGlobal(pos);
455 if (QTipLabel::instance->tipChanged(localPos, text, w)){
456 QTipLabel::instance->reuseTip(text, msecDisplayTime, pos);
457 QTipLabel::instance->setTipRect(w, rect);
458 QTipLabel::instance->placeTip(pos, w);
464 if (!text.isEmpty()) {
465 QWidget *tipLabelParent = [w]() -> QWidget* {
475 new QTipLabel(text, pos, tipLabelParent, msecDisplayTime);
476 QWidgetPrivate::get(QTipLabel::instance)->setScreen(QTipLabel::getTipScreen(pos, w));
477 QTipLabel::instance->setTipRect(w, rect);
478 QTipLabel::instance->placeTip(pos, w);
479 QTipLabel::instance->setObjectName(
"qtooltip_label"_L1);
481#if QT_CONFIG(effects)
482 if (QApplication::isEffectEnabled(Qt::UI_FadeTooltip))
483 qFadeEffect(QTipLabel::instance);
484 else if (QApplication::isEffectEnabled(Qt::UI_AnimateTooltip))
485 qScrollEffect(QTipLabel::instance);
487 QTipLabel::instance->showNormal();
489 QTipLabel::instance->showNormal();