fix(tooltip): 替换Tooltip,修复反复触发tooltip问题

This commit is contained in:
hewenfei 2024-04-22 15:13:49 +08:00
parent 7a52fc5d45
commit 0d0916fc34
4 changed files with 49 additions and 56 deletions

View File

@ -18,6 +18,15 @@ MouseArea {
border.width: 2 border.width: 2
} }
} }
UkuiItems.Tooltip {
anchors.fill: parent
mainText: name
posFollowCursor: true
margin: 6
visible: content.textTruncated
}
UkuiItems.StyleBackground { UkuiItems.StyleBackground {
id: controlBase id: controlBase
anchors.fill: parent anchors.fill: parent
@ -25,9 +34,6 @@ MouseArea {
useStyleTransparency: false useStyleTransparency: false
paletteRole: Platform.Theme.Text paletteRole: Platform.Theme.Text
alpha: isSelect ? 1.00 : control.containsPress ? 0.16 : control.containsMouse ? 0.08 : 0.00 alpha: isSelect ? 1.00 : control.containsPress ? 0.16 : control.containsMouse ? 0.08 : 0.00
ToolTip.visible: content.textTruncated && control.containsMouse
ToolTip.text: name
ToolTip.delay: 500
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent

View File

@ -12,15 +12,14 @@ MouseArea {
property bool isSelect: false property bool isSelect: false
hoverEnabled: true hoverEnabled: true
ToolTip { UkuiItems.Tooltip {
property bool isVisible: !editStatus && truncate && control.containsMouse anchors.fill: parent
id: tip mainText: name
x: mouseX + 15 posFollowCursor: true
y: mouseY + 15 margin: 6
text: name visible: !editStatus && truncate
visible: !editStatus && truncate && control.containsMouse
delay: 500
} }
onPositionChanged: { onPositionChanged: {
if (tip.isVisible) { if (tip.isVisible) {
if (tip.visible) { if (tip.visible) {

View File

@ -53,9 +53,13 @@ UkuiItems.StyleBackground {
width: height width: height
height: parent.height height: parent.height
ToolTip.delay: 500 UkuiItems.Tooltip {
ToolTip.text: modelData.toolTip anchors.fill: parent
ToolTip.visible: modelData.toolTip !== "" && containsMouse mainText: modelData.toolTip
posFollowCursor: true
margin: 6
visible: modelData.toolTip !== ""
}
background.radius: width / 2 background.radius: width / 2
background.paletteRole: Platform.Theme.Highlight background.paletteRole: Platform.Theme.Highlight

View File

@ -42,18 +42,14 @@ Item {
Layout.preferredHeight: 36 Layout.preferredHeight: 36
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
UkuiItems.ToolTip.text: mainWindow.isFullScreen ? qsTr("Contract") : qsTr("Expand") UkuiItems.Tooltip {
anchors.fill: parent
onEntered: { mainText: mainWindow.isFullScreen ? qsTr("Contract") : qsTr("Expand")
UkuiItems.ToolTip.show(fullScreenButton.mapToGlobal(0, fullScreenButton.height)); posFollowCursor: true
} margin: 6
onExited: {
UkuiItems.ToolTip.hide();
} }
onClicked: { onClicked: {
UkuiItems.ToolTip.hide();
if (mainWindow.isFullScreen) { if (mainWindow.isFullScreen) {
mainWindow.exitFullScreen(); mainWindow.exitFullScreen();
} else { } else {
@ -93,14 +89,11 @@ Item {
icon.width: 24 icon.width: 24
icon.height: 24 icon.height: 24
UkuiItems.ToolTip.text: totalUtils.realName UkuiItems.Tooltip {
anchors.fill: parent
onEntered: { mainText: totalUtils.realName
UkuiItems.ToolTip.show(userInfoButton.mapToGlobal(0, userInfoButton.height)); posFollowCursor: true
} margin: 6
onExited: {
UkuiItems.ToolTip.hide();
} }
onClicked: totalUtils.openUserCenter() onClicked: totalUtils.openUserCenter()
@ -122,14 +115,11 @@ Item {
Layout.preferredHeight: 36 Layout.preferredHeight: 36
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
UkuiItems.ToolTip.text: qsTr("Computer") UkuiItems.Tooltip {
anchors.fill: parent
onEntered: { mainText: qsTr("Computer")
UkuiItems.ToolTip.show(computerButton.mapToGlobal(0, computerButton.height)); posFollowCursor: true
} margin: 6
onExited: {
UkuiItems.ToolTip.hide();
} }
onClicked: { onClicked: {
@ -153,14 +143,11 @@ Item {
Layout.preferredHeight: 36 Layout.preferredHeight: 36
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
UkuiItems.ToolTip.text: qsTr("Control center") UkuiItems.Tooltip {
anchors.fill: parent
onEntered: { mainText: qsTr("Control center")
UkuiItems.ToolTip.show(setButton.mapToGlobal(0, setButton.height)); posFollowCursor: true
} margin: 6
onExited: {
UkuiItems.ToolTip.hide();
} }
onClicked: { onClicked: {
@ -184,7 +171,12 @@ Item {
Layout.preferredHeight: 36 Layout.preferredHeight: 36
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
UkuiItems.ToolTip.text: powerButtonBase.toolTip UkuiItems.Tooltip {
anchors.fill: parent
mainText: powerButtonBase.toolTip
posFollowCursor: true
margin: 6
}
PowerButton { PowerButton {
id: powerButtonBase id: powerButtonBase
@ -199,14 +191,6 @@ Item {
} }
} }
onEntered: {
UkuiItems.ToolTip.show(powerButton.mapToGlobal(0, powerButton.height));
}
onExited: {
UkuiItems.ToolTip.hide();
}
onClicked: { onClicked: {
var buttonPosition = mapToGlobal(width, height); var buttonPosition = mapToGlobal(width, height);
powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen); powerButtonBase.clicked(mouse.button === Qt.LeftButton, buttonPosition.x + spacingFromMenu, buttonPosition.y + spacingFromMenu, mainWindow.isFullScreen);