Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML ToolTip delay property is not working
Forum Updated to NodeBB v4.3 + New Features

QML ToolTip delay property is not working

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qt quickqml5.7tooltip
3 Posts 2 Posters 2.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Julien BJ Offline
    Julien BJ Offline
    Julien B
    wrote on last edited by Julien B
    #1

    Hello all,

    I encounter a problem with the delay property in QML ToolTip

    I first tried to add a simple TooTip to a button with Attached Porperty delay and timeout

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        visible: true
        width: 640; height: 480
        title: qsTr("Hello World")
        Rectangle {
            anchors.fill: parent
            color: "#ff202020"
    
            Button {
                anchors.centerIn: parent
                width: 196; height: 64
    
                contentItem: Text {
                    text: "Button"
                    color: parent.pressed ?"#ff202020":"#ffffffff"
                    font.pixelSize: 32
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
    
                background: Rectangle {
                    color: parent.pressed ? "#ffffffff":"#00000000"
                    border.color: "#ffffffff"
                    border.width: 2
                    anchors.fill: parent
                }
    
                ToolTip.visible: pressed
                ToolTip.delay: 1000
                ToolTip.timeout: 3000
                ToolTip.text: qsTr("Simple Tool tip attached to \"Button\" with several lines of text")
    
            }
        }
    }
    

    It works fine but I need to use a customized version of the ToolTip, so I changed it to the version below

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        visible: true
        width: 640; height: 480
        title: qsTr("Hello World")
        Rectangle {
            anchors.fill: parent
            color: "#ff202020"
    
            Button {
                anchors.centerIn: parent
                width: 196; height: 64
    
                contentItem: Text {
                    text: "Button"
                    color: parent.pressed ?"#ff202020":"#ffffffff"
                    font.pixelSize: 32
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
    
                background: Rectangle {
                    color: parent.pressed ? "#ffffffff":"#00000000"
                    border.color: "#ffffffff"
                    border.width: 2
                    anchors.fill: parent
                }
    
                ToolTip {
                    visible: parent.pressed
                    delay: 1000
                    timeout: 3000
    
                    contentItem: Text {
                        text: qsTr("Simple Tool tip attached to \"Button\" with several lines of text")
                        font.pixelSize: 24
                        wrapMode: Text.WordWrap
                        color: "#ffffff"
                        verticalAlignment: Text.AlignVCenter
                    }
    
                    background: Rectangle {
                        implicitHeight: 64
                        radius: 8
                        color: "#ff404040"
                    }
                }
    
            }
        }
    }
    

    The style is applied, the timeout still works but the delay does not work anymore and I don't understand why.

    Does someone have an idea?

    1 Reply Last reply
    0
    • Julien BJ Offline
      Julien BJ Offline
      Julien B
      wrote on last edited by Julien B
      #2

      I might have found where the problem comes from, it looks like it is related to the visible property.

      I read back the ToolTip documentation several time, then I took time to seek informations in the source code and here what I found out.

      QQuickToolTipAttached inherit from QObject and define visible property. Through Q_PROPERTY it use WRITE method QQuickToolTipAttached::setVisible, which call QQuickToolTipAttached::show, which call QQuickToolTip::open.

      It is this QQuickToolTip::open method which manage the delay before opening the ToolTip.

      While QQuickToolTip inherit from QQuickPopup and do not redefine visible property, so it use QQuickPopup::setVisible which do not call QQuickToolTip::open so there is no delay managed before opening.

      It seems to explain the differents behavior for visible property between the standard and attached version.

      However does someone know if that is a bug or this is the normal behavior?


      Anyway I found a workaround by adding this to my ToolTip:

      property bool show
      id: toolTip
      
      show: parent.pressed
      onShowChanged: {
          if (show)
              toolTip.open();
          else
              toolTip.close();
      }
      

      The code below contain standard customized version and attached version and they now work the same way:

      Rectangle {
          anchors.fill: parent
          color: "#ff202020"
      
          Row {
              anchors.centerIn: parent
              spacing: 16
      
              Button {
                  width: 256; height: 64
                  //hoverEnabled: true
      
                  contentItem: Text {
                      text: "Standard"
                      color: parent.pressed ?"#ff202020":"#ffffffff"
                      font.pixelSize: 28
                      horizontalAlignment: Text.AlignHCenter
                      verticalAlignment: Text.AlignVCenter
                  }
      
                  background: Rectangle {
                      color: parent.pressed ? "#ffffffff":"#00000000"
                      border.color: "#ffffffff"
                      border.width: 2
                      anchors.fill: parent
                  }
      
                  ToolTip {
                      property bool show
                      id: toolTip
                      delay: 1000
                      timeout: 5000
      
                      show: parent.pressed //|| parent.hovered
                      onShowChanged: {
                          if (show)
                              toolTip.open();
                          else
                              toolTip.close();
                      }
      
                      contentItem: Text {
                          text: qsTr("Customized tool tip link to \"Standard\" button with several lines of text")
                          font.pixelSize: 24
                          wrapMode: Text.WordWrap
                          color: "#ffffff"
                          verticalAlignment: Text.AlignVCenter
                      }
      
                      background: Rectangle {
                          implicitHeight: 64
                          radius: 8
                          color: "#ff00b374"
                      }
                  }
              }
      
              Button {
                  width: 256; height: 64
                  //hoverEnabled: true
      
                  contentItem: Text {
                      text: "Attached"
                      color: parent.pressed ?"#ff202020":"#ffffffff"
                      font.pixelSize: 28
                      horizontalAlignment: Text.AlignHCenter
                      verticalAlignment: Text.AlignVCenter
                  }
      
                  background: Rectangle {
                      color: parent.pressed ? "#ffffffff":"#00000000"
                      border.color: "#ffffffff"
                      border.width: 2
                      anchors.fill: parent
                  }
      
                  ToolTip.visible: pressed //|| hovered
                  ToolTip.delay: 1000
                  ToolTip.timeout: 5000
                  ToolTip.text: qsTr("Simple tool tip link to \"Attached\" button with several lines of text")
              }
          }
      }
      
      1 Reply Last reply
      0
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        Hi, this ToolTip bug has been fixed in Qt 5.7.1, which should be released very soon.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved