From c662dadd4a1543758f57bcf4a98e270d75b398ba Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Thu, 14 Dec 2023 19:15:13 +0100 Subject: [PATCH] Set correct content size for tool tip label The tool tip content size uses an incorrect content margin, when it's constructed. This content margin has been reset to correct value when tool tip is positioned using placeTip(). But after that, the content size not been recalculated. This patch triggers updatesSize() to calculate content size with updated content margin values. Fixes: QTBUG-119752 Pick-to: 6.5 Change-Id: I454c8528505686f2724b897e4002f78f3049149a Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer (cherry picked from commit e977a629277796880d1557e4841f731d1ef27c06) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 8dcb5814e09adb540fb5df69d759d1fdbfabe287) --- src/widgets/kernel/qtooltip.cpp | 8 +++--- .../widgets/kernel/qtooltip/tst_qtooltip.cpp | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 2800f65ac62..90c9e6dccbb 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -356,10 +356,12 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w) if (w) { connect(w, SIGNAL(destroyed()), QTipLabel::instance, SLOT(styleSheetParentDestroyed())); - // QTBUG-64550: A font inherited by the style sheet might change the size, - // particular on Windows, where the tip is not parented on a window. - QTipLabel::instance->updateSize(pos); } + // QTBUG-64550: A font inherited by the style sheet might change the size, + // particular on Windows, where the tip is not parented on a window. + // The updatesSize() also makes sure that the content size be updated with + // correct content margin. + QTipLabel::instance->updateSize(pos); } #endif //QT_NO_STYLE_STYLESHEET diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index 282eacd2ef5..082d30c67b8 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -26,6 +26,7 @@ private slots: void setPalette(); void qtbug64550_stylesheet(); void dontCrashOutsideScreenGeometry(); + void marginSetWithStyleSheet(); }; void tst_QToolTip::init() @@ -214,5 +215,30 @@ void tst_QToolTip::dontCrashOutsideScreenGeometry() { QToolTip::hideText(); } +void tst_QToolTip::marginSetWithStyleSheet() +{ + const char *toolTipText = "Test Tool Tip"; + + qApp->setStyleSheet("QToolTip {font-size: 8px; margin: 5px;}"); + QToolTip::showText(QGuiApplication::primaryScreen()->availableGeometry().topLeft(), toolTipText); + QTRY_VERIFY(QToolTip::isVisible()); + QWidget *toolTip = findToolTip(); + QVERIFY(toolTip); + QTRY_VERIFY(toolTip->isVisible()); + int toolTipHeight = toolTip->size().height(); + qApp->setStyleSheet(QString()); + QToolTip::hideText(); + + qApp->setStyleSheet("QToolTip {font-size: 8px; margin: 10px;}"); + QToolTip::showText(QGuiApplication::primaryScreen()->availableGeometry().topLeft(), toolTipText); + QTRY_VERIFY(QToolTip::isVisible()); + toolTip = findToolTip(); + QVERIFY(toolTip); + QTRY_VERIFY(toolTip->isVisible()); + QCOMPARE_LE(toolTip->size().height(), toolTipHeight + 10); + qApp->setStyleSheet(QString()); + QToolTip::hideText(); +} + QTEST_MAIN(tst_QToolTip) #include "tst_qtooltip.moc"