How to show/hide KDE plasmoid's tooltip programatically?

255 Views Asked by At

Is there a way to make a plasmoid tooltip to show/hide programatically?

I tried by setting a ToolTipArea over the compact representation, and trying to trigger it with a Timer - it does not work (the regular tooltip keeps showing but only when hovering the plasmoid icon (aka compactRepresentation):

import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

Item {
    Layout.preferredWidth: 200
    Layout.preferredHeight: 300

    Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation

    Plasmoid.compactRepresentation: Item
    {
        anchors.fill: parent

        MouseArea
        {
            onClicked:
            {
                 plasmoid.expanded = !plasmoid.expanded
            }
        }

        PlasmaCore.ToolTipArea
        {
            id: toolTip
            width: parent.width
            height: parent.height
            anchors.fill: parent
            mainItem: tooltipContentItem
            active: false
            interactive: true
        }

        Timer
        {
            interval: 3000
            running: true
            repeat: true
            onTriggered:
            {
                if (tooltipContentItem.active == false)
                {
                    toolTip.showToolTip()
                    toolTip.active == true
                }

                else
                {
                    toolTip.hideToolTip()
                    toolTip.active == false
                }
            }
        }
    }

    Item
    {
        id: tooltipContentItem

        implicitWidth: 300
        implicitHeight: 200

        ColumnLayout
        {
            id: mainLayout
            anchors
            {
                left: parent.left
                top: parent.top
                margins: PlasmaCore.Units.gridUnit / 2
            }

            PlasmaExtras.Heading
            {
                id: tooltipMaintext
                level: 3
                Layout.minimumWidth: Math.min(implicitWidth, preferredTextWidth)
                Layout.maximumWidth: preferredTextWidth
                elide: Text.ElideRight
                text: "Test"
            }

            PlasmaComponents.Label
            {
                id: tooltipSubtext
                Layout.minimumWidth: Math.min(implicitWidth, preferredTextWidth)
                Layout.maximumWidth: preferredTextWidth
                text: "Testing text"
                opacity: 0.6
            }
        }
    }
}

There's the toolTipItem QQuickItem too, but I cannot figure out if it is possible to make it show or hide on command (this bit was borrowed from KDE's digitalclock plasmoid:

import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

Item {
    Layout.preferredWidth: 200
    Layout.preferredHeight: 300

    Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation

    Plasmoid.compactRepresentation: Item
    {
        anchors.fill: parent

        MouseArea
        {
            onClicked:
            {
                 plasmoid.expanded = !plasmoid.expanded
            }
        }
    }

    plasmoid.toolTipItem: Loader
    {
        id: toolTipLoader
        source: "Tooltip.qml" // Just holds the tooltip contents
    }
}
0

There are 0 best solutions below