Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-78202

QML ToolTip is closed unexpectedly

    XMLWordPrintable

Details

    • f4d5939ad613fda69aa750139ef929fac18b97ae (qt/qtquickcontrols2/5.14)

    Description

      QML ToolTip is closed unexpectedly if another QML Item with set attached ToolTip.text property is instantiated.

       

      Here in example green rectangle has ToolTip.visible property bound to mouseArea.containsMouse

      When Loader instantiates another item with ToolTip attached property, even if this another item has ToolTip.visible: false, something happens with bindings and shared instance of ToolTip is closed.

       

      import QtQuick 2.12
      import QtQuick.Controls 2.12
      import QtQuick.Window 2.12
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle {
              color: "green"
              height: 100
              anchors {
                  top: parent.top
                  left: parent.left
                  right: parent.right
                  margins: 20
              }
      
              MouseArea {
                  id: mouseArea
                  anchors.fill: parent
                  hoverEnabled: true
                  onClicked: loader.active = !loader.active
      
                  onContainsMouseChanged: console.log("Green hovered changed: " + containsMouse)
              }
      
              Text {
                  anchors.centerIn: parent
                  text: "Click me!"
              }
      
              ToolTip.text: "This tooltip should not disappear after click"
              ToolTip.visible: mouseArea.containsMouse
              ToolTip.onVisibleChanged: {
                  console.log("Green ToolTip.visible changed: " + ToolTip.visible)
                  if (ToolTip.visible !== mouseArea.containsMouse) {
                      console.log("DAFUQ?")
                  }
              }
          }
      
          Rectangle {
              height: 100
              anchors {
                  verticalCenter: parent.verticalCenter
                  left: parent.left
                  right: parent.right
                  margins: 20
              }
              color: "blue"
      
              MouseArea {
                  anchors.fill: parent
                  hoverEnabled: true
      
                  ToolTip.text: "This tooltip doesn't matter"
                  ToolTip.visible: containsMouse
              }
          }
      
          Loader {
              id: loader
              active: false
              height: 100
              anchors {
                  bottom: parent.bottom
                  left: parent.left
                  right: parent.right
                  margins: 20
              }
      
              sourceComponent: Rectangle {
                  color: "red"
                  ToolTip.text: "Oops"
                  ToolTip.visible: false
      
                  ToolTip.onVisibleChanged: console.log("Red ToolTip.visible changed: " + ToolTip.visible)
      
                  Text {
                      anchors.centerIn: parent
                      text: "Hi! I just closed your ToolTip for green rect :p"
                  }
              }
          }
      
          ToolTip.toolTip.onOpened: console.log("ToolTip opened with text: " + ToolTip.toolTip.text)
          ToolTip.toolTip.onClosed: console.log("ToolTip closed with text: " + ToolTip.toolTip.text)
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            wang_chuan wang chuan
            sergei.nevdakh Sergei Nevdakh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes