如何在qt quick controls2中更改ToolTip的字体?

时间:2018-03-09 05:12:14

标签: qt qml qtquick2 qtquickcontrols2

我想更改ToolTip的字体系列,但我收到了以下错误

  

QQmlApplicationEngine无法加载组件

     

qrc:/main.qml:132类型BookPage不可用

     

qrc:/pages/BookPage.qml:41类型BookItem不可用

     

qrc:/pages/BookItem.qml:102 无法分配给不存在的属性“font”

ToolButton{
    id: tbtnStatistics

    ToolTip.visible:down
    ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
    ToolTip.text: "This is Tooltip"
    ToolTip.font.family: "tahoma"
    ToolTip.timeout: 4000

    contentItem: Image {
        fillMode: Image.Pad
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        source: "../images/statistics.png"
    }
}

1 个答案:

答案 0 :(得分:1)

QML不支持多层嵌套,因此通常会观察到这类问题,如下所示减少它是合适的:

ToolButton{
    id: tbtnStatistics

    ToolTip{
        visible: tbtnStatistics.down
        delay: Qt.styleHints.mousePressAndHoldInterval
        text: "This is Tooltip"
        font.family: "tahoma"
        timeout: 4000
    }

    contentItem: Image {
        fillMode: Image.Pad
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        source: "../images/statistics.png"
    }
}