问题
Here's the definition of my PathButton.qml
:
import QtQuick 2.0
import QtQuick.Shapes 1.12
import QtQuick.Controls 2.5
Item {
property alias pathData: svg.path
property alias toolTip: tip.text
signal clicked()
width: 28
height: width
Shape{
transform: Scale{ xScale: 1.2; yScale: 1.2}
ShapePath{
id: path
fillColor: "black"
PathSvg{
id: svg
path: pathData
}
}
}
ToolTip{
id: tip
visible: area.containsMouse
}
MouseArea{
id: area
anchors.fill: parent
onClicked: parent.clicked()
hoverEnabled: true
onHoveredChanged: path.fillColor = containsMouse? "blue" : "black"
}
}
and in main.qml
, I've used that to Maximize and Restore the window with this:
Window {
...
id: mainWindow
PathButton{
pathData: mainContext.maximizeIcon
toolTip: "Maximize"
onClicked: {
if(mainWindow.visibility == Window.Maximized){
mainWindow.showNormal()
pathData = mainContext.maximizeIcon
toolTip: "Restore"
}
else {
mainWindow.showMaximized()
pathData = mainContext.restoreIcon
toolTip: "Maximize"
}
}
}
...
}
and it does its job and changes pathData
BUT doesn't change the toolTip
, it always shows Maximize
!
来源:https://stackoverflow.com/questions/62719627/tooltip-text-doesnt-change