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 show multiple Popup on a window? (for ToolTip)
Forum Updated to NodeBB v4.3 + New Features

How to show multiple Popup on a window? (for ToolTip)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 389 Views 1 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.
  • W Offline
    W Offline
    wooseokyourself
    wrote on 2 Dec 2021, 09:17 last edited by wooseokyourself 12 Feb 2021, 09:19
    #1

    Hi. I want to show all ToolTips of buttons when a helper button's clicking triggered.
    I could do it with only a button with ToolTip.show("Some instruction", -1), but when I called this method with more than 1 buttons, only last called ToolTip show itself.
    I found the ToolTip inherits Popup, so I think I can solve my problem if I can make multiple Popups to show on a window.
    Below is what I wanted to do. Any ideas?

    Button {
        id: helperButton
        text: "Help"
        onClicked: {
            otherButton1.ToolTip.show("button 1's instruction", -1)
            otherButton2.ToolTip.show("button 2's instruction", -1)
            otherButton3.ToolTip.show("button 3's instruction", -1)
        }
    }
    
    /// Result: Only ToolTip of @otherButton3 shows. I want all buttons' ToolTip show at the same time.
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 2 Dec 2021, 15:35 last edited by
      #2

      As mentioned in the documentation, when using attached ToolTips, you can only have one visible at a time.
      To have more than one, you need to have standalone ToolTip instances ( https://doc.qt.io/qt-5/qml-qtquick-controls2-tooltip.html#custom-tool-tips )

      You could do that with an Instantiator for example:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      
      Window {
          width: 640
          height: 480
          visible: true
      
          Button {
              text: "Show tooltips"
              onClicked: toolTipTimer.start()
          }
      
          Column {
              anchors.centerIn: parent
              spacing: 32
              Button {
                  id: button1
                  text: "Button 1"
              }
              Button {
                  id: button2
                  text: "Button 2"
              }
              Button {
                  id: button3
                  text: "Button 3"
              }
          }
          Timer {
              id: toolTipTimer
              interval: 4000
          }
          Instantiator {
              active: toolTipTimer.running
              model: [
                  { item: button1, description: "button 1's instruction" },
                  { item: button2, description: "button 2's instruction" },
                  { item: button3, description: "button 3's instruction" },
              ]
              delegate: ToolTip {
                  visible: true
                  parent: modelData.item
                  text: modelData.description
              }
          }
      }
      

      Here I've used a static model, but you could also have used column.children with each button storing its tooltip text and using that in the ToolTip delegate for its text.

      1 Reply Last reply
      1
      • W Offline
        W Offline
        wooseokyourself
        wrote on 2 Dec 2021, 16:12 last edited by
        #3

        @GrecKo
        Nice and good example! I can solve my problem. Thanks.

        1 Reply Last reply
        0

        1/3

        2 Dec 2021, 09:17

        • Login

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