Skip to content

Commit f0865b5

Browse files
committed
fix: tooltip does not show the latest text
在这paintEvent中判断文本是否发生变化,如果变化了则调用DToolTip::setShowToolTip(this, false)重置状态, 确保Tooltip能显示最新的文本内容。为此在DLabelPrivate中增加了lastText成员变量用于记录上一次的文本。 Check if the text has changed in paintEvent. If it has changed, call DToolTip::setShowToolTip(this, false) to reset the status, ensuring that the Tooltip displays the latest text content. To achieve this, a lastText member variable was added to DLabelPrivate to record the previous text. Log: fix tooltip does not show the latest text Pms: BUG-300837
1 parent 7446242 commit f0865b5

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/widgets/dlabel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ void DLabel::paintEvent(QPaintEvent *event)
207207
palette.setBrush(foregroundRole(), DPaletteHelper::instance()->palette(this).brush(d_func()->color));
208208
}
209209

210+
if (!d->text.isEmpty() && d->text != d_func()->lastText) {
211+
// clear flag when text changed, avoid tooltip don't show new text
212+
DToolTip::setShowToolTip(this, false);
213+
}
214+
d_func()->lastText = d->text;
215+
210216
QString text = d->text;
211217
if (elideMode() != Qt::ElideNone) {
212218
const QFontMetrics fm(fontMetrics());

src/widgets/private/dlabel_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class DLabelPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
2727

2828
DPalette::ColorType color = DPalette::NoType;
2929
Qt::TextElideMode elideMode = Qt::ElideNone;
30+
QString lastText;
3031
};
3132

3233
DWIDGET_END_NAMESPACE

0 commit comments

Comments
 (0)