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. How to set ToolTip's properties (delay, timeout, etc) globally?
Forum Updated to NodeBB v4.3 + New Features

How to set ToolTip's properties (delay, timeout, etc) globally?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 2.3k Views
  • 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.
  • J Offline
    J Offline
    J0hnny
    wrote on last edited by
    #1

    Is there a way to set ToolTip's properties like "delay", "timeout" and "visible" globally in an application to avoid boilerplate code which sets the same properties in each item which needs a ToolTip? It seems like a standard use case when all controls have the same behavior of tooltips in an app, isn't it?
    Below is an example of using setTooltipProperties() to minimize code duplication, but still it looks like boilerplate code. It works for both desktop (mouse) and mobile (touch).

    import QtQuick 2.8
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    import QtQuick.Layouts 1.3
    
    Window {
        id: window
        visible: true
        width: 640
        height: 480
        property bool isDesktop: switch (Qt.platform.os) {
                                 case "android":
                                 case "ios":
                                     return false;
                                 default:
                                     return true;
                                 }
    
        function setTooltipProperties(tooltip, target)
        {
            tooltip.visible = Qt.binding(function () {
                return tooltip.text === "" ?
                            false
                          :  isDesktop ? target.hovered : target.pressed
            })
    
            tooltip.delay = 2000
            tooltip.timeout = 3000
        }
    
        ColumnLayout {
            Button {
                text: "1"
                ToolTip.text: "Tooltip 1"
                Component.onCompleted: setTooltipProperties(ToolTip, this)
            }
    
            Button {
                text: "2"
                ToolTip.text: "Tooltip 2"
                Component.onCompleted: setTooltipProperties(ToolTip, this)
            }
        }
    }
    
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      arozon
      wrote on last edited by arozon
      #2

      You could attempt to build your own ToolTip and self manage it?

      Using a Timer to count after a onEnter for the specific control, and then count again for a timeout, stopping the timer on an exit...

      Use rectangle with a label inside and size it in accordance with the text size and a bit of padding to make it fancy... Will give you much more control and you can basically add anything to the tooltip

      use connections between your controls events to functions that manage the timer

      1 Reply Last reply
      0

      • Login

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