Skip to content

Commit 55696f0

Browse files
committed
Fix: Optimize tooltip positioning logic.
Log: The Popup is rendered on the window's Overlay layer and is not part of the content visual tree. As a result, the tooltip does not follow its anchor item during scrolling or window resizing, causing positional drift. To resolve this, AlertToolTip has been changed from a ToolTip (which uses Popup) to a regular Item, making it part of the content visual tree. This ensures it naturally scrolls with its parent, respects container clipping, and maintains correct positioning at all times. PMS: bug-341973
1 parent 6fe5e85 commit 55696f0

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

qt6/src/qml/AlertToolTip.qml

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
1-
// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

55
import QtQuick
66
import org.deepin.dtk 1.0 as D
77
import org.deepin.dtk.style 1.0 as DS
88

9-
ToolTip {
9+
Control {
1010
id: control
1111
property Item target
12+
property string text
13+
property int timeout: 0
14+
property bool _expired: false
15+
readonly property bool _shown: control.visible && !_expired
1216

1317
x: 0
14-
y: target ? target.height + DS.Style.control.spacing : 0
18+
y: (target ? target.height : 0) + (_shown ? DS.Style.control.spacing : 0)
19+
Behavior on y {
20+
NumberAnimation { duration: 200 }
21+
}
22+
opacity: _shown ? 1 : 0
23+
enabled: _shown
1524
topPadding: DS.Style.alertToolTip.verticalPadding
1625
bottomPadding: DS.Style.alertToolTip.verticalPadding
1726
leftPadding: DS.Style.alertToolTip.horizontalPadding
1827
rightPadding: DS.Style.alertToolTip.horizontalPadding
19-
implicitWidth: Math.min(DS.Style.control.implicitWidth(control), target.width)
28+
implicitWidth: target ? Math.min(DS.Style.control.implicitWidth(control), target.width) : DS.Style.control.implicitWidth(control)
2029
implicitHeight: DS.Style.control.implicitHeight(control)
21-
margins: 0
22-
closePolicy: Popup.NoAutoClose
30+
z: D.DTK.TopOrder
31+
32+
Timer {
33+
id: autoHideTimer
34+
interval: control.timeout
35+
running: control.timeout > 0 && control.visible && !control._expired
36+
onTriggered: control._expired = true
37+
}
38+
39+
onVisibleChanged: {
40+
_expired = false
41+
if (visible && timeout > 0)
42+
autoHideTimer.restart()
43+
}
44+
45+
onTextChanged: {
46+
_expired = false
47+
if (visible && timeout > 0)
48+
autoHideTimer.restart()
49+
}
2350

2451
background: FloatingPanel {
2552
radius: DS.Style.alertToolTip.radius
@@ -40,23 +67,12 @@ ToolTip {
4067
wrapMode: Text.Wrap
4168
}
4269

43-
enter: Transition {
44-
// TODO: Transparency causes tooltips to appear through the window background - temporarily removed
45-
// NumberAnimation { properties: "opacity"; from: 0.0; to: 1.0; duration: 200 }
46-
NumberAnimation { properties: "y"; from: control.target.height; to: control.target.height + DS.Style.control.spacing; duration: 200 }
47-
}
48-
49-
exit: Transition {
50-
// NumberAnimation { properties: "opacity"; from: 1.0; to: 0.0 }
51-
NumberAnimation { properties: "y"; from: control.target.height + DS.Style.control.spacing ; to: control.target.height }
52-
}
53-
5470
BoxShadow {
5571
id: line
5672
property D.Palette dropShadowColor: DS.Style.alertToolTip.connecterdropShadow
5773
property D.Palette backgroundColor: DS.Style.alertToolTip.connecterBackground
5874
property D.Palette borderColor: DS.Style.control.border
59-
y: - height * (0.75) - control.topMargin - control.topPadding
75+
y: -height * 0.75
6076
width: DS.Style.alertToolTip.connectorWidth
6177
height: DS.Style.alertToolTip.connectorHeight
6278
shadowBlur: 4

qt6/src/qml/EditPanel.qml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ Rectangle {
3131
}
3232
}
3333

34+
// Keep Loader active while there is alert text so we don't destroy/recreate when
35+
// caller toggles showAlert to refresh the message; avoids wrong text (e.g. "systemd journal")
36+
// from binding context during recreation.
3437
Loader {
35-
active: showAlert && alertText.length !== 0
38+
active: alertText.length !== 0
3639
sourceComponent: AlertToolTip {
3740
target: control
3841
timeout: alertDuration

0 commit comments

Comments
 (0)