November 10, 2010

cbrake cbrake
Lab Rat
17 posts

recommended approach for displaying tooltips

 

Hello,

I have a QML application with a number of buttons and would like to display a “tooltip” when the mouse is over top the button. What is the recommended way to do this with QML?

Thanks,
Cliff

4 replies

November 10, 2010

Alexander Kuchumov Alexander Kuchumov
Lab Rat
377 posts

Are you writing application for desktop platforms? I suppose – one way – writing your own code for this.

November 10, 2010

korzhp korzhp
Lab Rat
3 posts

look at http://qt.gitorious.org/qt-components

November 11, 2010

mbrasser mbrasser
Ant Farmer
452 posts

Hi,

You should be able to emulate tooltips using the basic QML items. Here’s an example — its not very pretty, and very limited (no delay, only one button, etc), but hopefully it will give you some ideas.

  1. import QtQuick 1.0
  2.  
  3. Rectangle {
  4.     width: 200
  5.     height: 200
  6.  
  7.     property bool needTooltip: button.hovered
  8.     property real tooltipX: button.x
  9.     property real tooltipY: button.y
  10.  
  11.     Rectangle {
  12.         id: button
  13.         property bool hovered: ma.containsMouse
  14.         width: 100; height: 100
  15.         anchors.centerIn: parent
  16.         color: "steelblue"
  17.         Text {
  18.             anchors.centerIn: parent
  19.             text: "My Button"
  20.         }
  21.         MouseArea {
  22.             id: ma
  23.             anchors.fill: parent
  24.             hoverEnabled: true
  25.         }
  26.     }
  27.  
  28.     Rectangle {
  29.         id: tooltip
  30.         width: 75; height: 20
  31.         visible: false
  32.         color: "red"
  33.         Text {
  34.             anchors.centerIn: parent
  35.             text: "My Tooltip"
  36.         }
  37.  
  38.         states: State {
  39.             name: "inuse"
  40.             when: needTooltip
  41.             PropertyChanges {
  42.                 target: tooltip
  43.                 visible: true
  44.                 x: tooltipX + 12
  45.                 y: tooltipY - 30
  46.             }
  47.         }
  48.     }
  49. }

Regards,
Michael

November 11, 2010

anselmolsm anselmolsm
Ant Farmer
417 posts
korzhp wrote:
look at http://qt.gitorious.org/qt-components

As korzhp said, take a look at Qt-Components. There you’ll find a QML implementation of the Mx toolkit; in src/Mx/ you find the implementation of a tooltip. Run examples/mx/test.qml to see it in action in the Mx widgets gallery :-)

 Signature 

Anselmo L. S. Melo (anselmolsm)
www.anselmolsm.org

 
  ‹‹ Change Mouse Cursor      Why is QtMobility required to use Multimedia in QML? ››

You must log in to post a reply. Not a member yet? Register here!