ToolTip.text doesn't change

℡╲_俬逩灬. 提交于 2020-07-23 06:35:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!