Getting A Tooltip (Qt)

Last edited on

How to use the Qt API via Squish to get a tooltip text

It is easy to use the Qt API to access tooltips or other application object properties.

Qt 4 and higher

You can directly check an object’s tooltip text (or any other property using the approach shown here).

JavaScript

function main() {
    startApplication("addressbook");



    // Verify a statically set tooltip text:
    var newButton = waitForObject(":Address Book.New_QToolButton");
    test.compare(newButton.toolTip, "New", "tool tip text for 'New'-button is set");



    // Verify a dynamically set tooltip text:

    // Move mouse over button and wait to ensure the
    // tooltip has been shown:
    mouseMove(newButton);
    snooze(2);

    // Use static method QToolTip.text():
    // http://doc.qt.io/qt-4.8/qtooltip.html#text
    test.compare(QToolTip.text(), "New", "tool tip for 'New'-button is shown");
}
test.js

Python

def main():
    startApplication("addressbook")



    # Verify a statically set tooltip text:
    new_button = waitForObject(":Address Book.New_QToolButton");
    test.compare(new_button.toolTip, "New", "tool tip text for 'New'-button is set")



    # Verify a dynamically set tooltip text:

    # Move mouse over button and wait to ensure the
    # tooltip has been shown:
    mouseMove(new_button)
    snooze(2)

    # Use static method QToolTip.text():
    # http://doc.qt.io/qt-4.8/qtooltip.html#text
    test.compare(QToolTip.text(), "New", "tool tip for 'New'-button is shown")
test.py

Qt 3

For Qt 3 it is necessary to use the QToolTip class (which is wrapped by Squish) to fetch the tooltip for a widget:

Python

def main():
  # Access the object using the symbolic name
  button = waitForObject(":Press Me!_QPushButton")

  # Get the tooltip text
  toolTipText = QToolTip.textFor( button )

  # Print it into the test log
  test.log("This is the tooltip text: " + str(toolTipText))

  # Compare it to a string, the result is printed to the test log
  test.compare(str(toolTipText), "this will fail")
test.py

Tcl

proc main {} {
  # Access the object using the symbolic name
  set button [ waitForObject ":Press Me!_QPushButton" ]

  # Get the tooltip text
  set toolTipText [ toString [ inboke QToolTip textFor $button ] ]

  # Print it into the test log
  test log "This is the tooltip text: $toolTipText"

  # Compare it to a string, the result is printed to the test log
  test compare $toolTipText "this will fail"
}
test.tcl