组件的 QML 工具提示

num*_*her 1 qt qml

我想为a 中的ToolTip代表做一个. 如果我使用 an ,它工作得很好,但是,我不能使用 an,因为它破坏了 的选择模式。如果我尝试在我的委托组件中定义,我会收到错误ComponentTableViewItemDelegateItemDelegateTableViewToolTip

 qrc:/FileSystem.qml:34 Invalid component body specification
Run Code Online (Sandbox Code Playgroud)

如何使用工具提示Component

这是我的代码:

TreeView {
    id: view
    anchors.fill: parent
    sortIndicatorVisible: true
    model: fileSystemModel
    rootIndex: rootPathIndex
    selection: sel
    selectionMode: 2
    Component {
        id: mycomp
        Row{
            id: myrow
            CheckBox{
                id: cbox
                anchors.baseline: ctext.baseline
            }
            Text{
                id: ctext
                text: styleData.value
                color: styleData.textColor
                width: namecolumn.width-cbox.width-myrow.x
                elide: Text.ElideRight
            }
        }
        NC.ToolTip {
            parent: mycomp
            visible: hovered
            delay: 1000
            text: qsTr(styleData.value)
        }
    }

    TableViewColumn {
        id: namecolumn
        title: "Name"
        role: "fileName"

        resizable: true
        width: parent.width-sizeWidth-dateWidth-scrollBarWidth
        delegate: mycomp

    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*her 5

一个组件必须由一个“子组件”组成。因此,您可以尝试将组件的内容包装到一个 Item 中,如下所示:

Component {
    Item {
        width: parent.width
        height: myrow.height

        Row{
            id: myrow
            CheckBox{
                id: cbox
                anchors.baseline: ctext.baseline
            }
            Text{
                id: ctext
                text: styleData.value
                color: styleData.textColor
                width: namecolumn.width-cbox.width-myrow.x
                elide: Text.ElideRight
            }
        }
        MouseArea {
            id: mouseArea
            anchors.fill: true
            hoverEnabled: true
        }
        NC.ToolTip {
            visible: mouseArea.containsMouse
            delay: 1000
            text: qsTr(styleData.value)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)