numberCruncher
numberCruncher

Reputation: 645

QML ToolTip for Component

I want to make a ToolTip for a delegate Component in a TableView. It works fine, if I use an ItemDelegate, however, I cannot use an ItemDelegate as it destroys the selection mode of TableView. If I try to define the ToolTip in my delegate component I get the error

 qrc:/FileSystem.qml:34 Invalid component body specification

How can I use a ToolTip for a Component?

Here is my code:

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

    }

Upvotes: 1

Views: 3677

Answers (1)

Martin Höher
Martin Höher

Reputation: 735

A component must consist of exactly one "child". So you could try to wrap the contents of the component into an Item, something like this:

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)
        }
    }
}

Upvotes: 5

Related Questions