fix: tooltip does not show the latest text#725
Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom Feb 3, 2026
Merged
fix: tooltip does not show the latest text#72518202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743 merged 1 commit intolinuxdeepin:masterfrom
Conversation
Contributor
Author
18202781743
reviewed
Feb 2, 2026
f0865b5 to
832decb
Compare
在这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
832decb to
3d4494c
Compare
Contributor
deepin pr auto review这段代码主要实现了在 1. 语法逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
5. 改进建议代码建议一:优化注释和变量初始化(保持原逻辑位置)如果必须保留在 dlabel_p.h // 在构造函数中初始化
DLabelPrivate::DLabelPrivate(DLabel *qq) : DObjectPrivate(qq)
, lastText() // 确保初始化为空
{
}
// ... 成员变量 ...
QString lastText;dlabel.cpp // ... paintEvent 中 ...
// 文本变更时重置提示标志,确保工具提示显示最新内容
if (d->text != d_func()->lastText) {
DToolTip::setShowToolTip(this, false);
d_func()->lastText = d->text;
}
// ...建议二:性能优化方案(推荐)将逻辑移至 dlabel_p.h class DLabelPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
{
public:
// ...
DPalette::ColorType color = DPalette::NoType;
Qt::TextElideMode elideMode = Qt::ElideNone;
// 如果仅仅为了 tooltip 逻辑,可能不再需要这个成员变量,
// 除非有其他地方依赖它。如果保留,需确保初始化。
QString lastText;
};dlabel.cpp // 假设存在或添加 setText 方法
void DLabel::setText(const QString &text)
{
// 只有文本真正改变时才处理
if (d_func()->text != text) {
// 调用基类设置文本
QLabel::setText(text); // 或者 DLabel 的基类
// 文本变更时重置提示标志,确保工具提示显示最新内容
DToolTip::setShowToolTip(this, false);
// 更新 lastText(如果后续逻辑仍需要它)
d_func()->lastText = text;
}
}
// paintEvent 可以移除相关逻辑,保持简洁
void DLabel::paintEvent(QPaintEvent *event)
{
// ... 原有绘制逻辑 ...
}总结原代码在功能上是可以工作的,但从性能角度看,在 |
18202781743
approved these changes
Feb 3, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在这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