Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Squish/Verifying the Existence of a Menu Item

From Qt Wiki
< Squish
Revision as of 15:00, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Verifying the existence of a menu item

To verify the existence of a menu item within a menu, there are multiple approaches: 1) accessing the QAction list supplied to us by the QWidget class through the Qt API or 2) using Squish’s real name to see if the object exists.

In the end, the usage of any of these approaches are as simple as:

Qt API approach

This approach uses the Qt API to access the menu and the menu’s actions, and then iterate through all of the actions to see if it contains the one we are looking for.

We start out by using the real name of the menu to identify it, as that gives us the ability to dynamically specify which menu Squish should be looking for. We then wait for it to exist, to make sure the script is not played back to fast, retrieve the QAction list from the menu and iterate through them, comparing the text property of QAction with the text we supply in the argument.

Squish’s real name approach

Similar to the approach above where we use the real name to get to the menu, we do the same thing but with the menu item instead.

At a first glance, the real name approach is easier, but consider also that the Qt API approach is much more powerful when we go beyond checking for just existance, such as making sure menu items all have shortcut keys or tooltips set.

Categories: