Qt Object's Identified Attributes

The cross-platform Qt technology is also an object recognition technology, that is, using the properties of objects to locate controls and perform automated operations.

See Model Objects and Attributes for some common identifying attributes.

Shared Identification Attributes

The identification properties used by Qt below have the same names as the object properties in other automation technologies such as Windows Automation, but may have different meanings.

type

The type of control, required attributes, cannot be changed and deleted, and affects the operation API provided by the control. Types such as Button, Text, Window, List, Table, Tree, etc.

name

The internal object name objectName property of the Qt control.

text

The text value of the control. If the control has properties such as text, label, and title set during development, since these properties are consistent with the content of the control seen by the user, this value is selected when the previous item is not satisfied;

If the control does not have the above values, it does not have this property by default.

className

The control class to which the control belongs comes from the class of the control in the code. For example, the control usually used as a window in Qt is QWidget, then the type of the window in the application is Window, and the className is QWidget, as shown in the following figure:

The className of the Qt control

Since the value of className depends on the specific components used in the development of the control, it represents the Qt components used by the control and can also be used to understand the application structure.

toolTip

The prompt information of the control. Some controls, such as picture buttons, do not have a text attribute, but have a fixed toolTip attribute, so they can also be used as identification attributes.

Distinctive Identification Attributes

Unique properties refer to identification properties that only exist in certain types of controls.

itemIndex

The index position of the target control in the container, stored in the tab page item TabItem, indicating the index position of the target tab page. Since the position of the tab page is variable, this identification attribute is usually matched with the text attribute of TabItem, and the matching rules are as follows:

  • Prioritize using text to identify attribute matches;
  • When the text identification attribute cannot be matched, or when multiple TabItem controls are matched, the itemIndex attribute will be used for identification;
  • Otherwise throw an error that the object cannot be found.

itemPath

The position of the target control in the entire view component exists in ListItem, TableItem, TreeItem and ViewItem, but there are some differences in the definition of paths in different types of item. Defined in the types file as follows:

JavaScript
export type ItemPath = number; // Commonly used in ListItem to indicate the list item position with a number.
export type ItemPath = number[]; // Commonly used in TreeItem to represent the path of a tree node with an array of numbers
export type ItemPath = string[]; // Commonly used in TreeItem, it uses an array of strings to represent the name path of a tree node, and will automatically find the matching tree node in the tree.
export type ItemPath = [number, number]; // Commonly used in TableItem, with rows and columns to form an array to represent the cell position.
export type ItemPath = [number, number][]; // Commonly used in TreeItem to represent the attributes of tree nodes in more complex arrays, similar to the rows of a table

position

Identification property for graphics-control. Represents the position of the graphic element in the canvas (scene), i.e. the value of the scenePos() property method of the QGraphicsItem control class.

bounding

Identification property for graphics-control. Represents the collision box of the graph element, i.e. the value of the boundingRect() property method of the QGraphicsItem control class.

objectName

Identification property used for graphics element control. The name of the graphic element, which belongs to the objectName() property method of the QGraphicsObject control class (a subclass of QObject and QGraphicsItem controls). A graphic element with this property can be positioned precisely, even if the position is moved, the canvas is changed or there are multiple duplicate elements.

So if you want to have better test-friendliness of the control generated by drawing in your application, you can have the drawn control derived from QGraphicsObject instead of QGraphicsItem.

results matching ""

    No results matching ""