Class ElementHandle¶
Defined in File slint-testing.h
Class Documentation¶
-
class ElementHandle¶
A handle to an element for querying accessible properties, intended for testing purposes.
Public Functions
-
inline bool is_valid() const¶
Returns true if the underlying element still exists; false otherwise.
-
inline std::optional<SharedString> id() const¶
Returns the element’s qualified id. Returns None if the element is not valid anymore or the element does not have an id. A qualified id consists of the name of the surrounding component as well as the provided local name, separate by a double colon.
,no-preview component PushButton { /* .. *‍/ } export component App { mybutton := PushButton { } // known as `App::mybutton` PushButton { } // no id }
-
inline std::optional<SharedString> type_name() const¶
Returns the element’s type name; std::nullopt if the element is not valid anymore.
,no-preview component PushButton { /* .. *‍/ } export component App { mybutton := PushButton { } // type_name is "PushButton" }
-
inline std::optional<SharedVector<SharedString>> bases() const¶
Returns the element’s base types as an iterator; None if the element is not valid anymore.
,no-preview component ButtonBase { /* .. *‍/ } component PushButton inherits ButtonBase { /* .. *‍/ } export component App { mybutton := PushButton { } // bases will be ["ButtonBase"] }
-
inline std::optional<slint::testing::AccessibleRole> accessible_role() const¶
Returns the value of the element’s
accessible-role
property, if present. Use this property to locate elements by their type/role, i.e. buttons, checkboxes, etc.
-
inline std::optional<SharedString> accessible_label() const¶
Returns the accessible-label of that element, if any.
-
inline std::optional<bool> accessible_enabled() const¶
Returns the accessible-enabled of that element, if any.
-
inline std::optional<SharedString> accessible_value() const¶
Returns the accessible-value of that element, if any.
-
inline std::optional<SharedString> accessible_placeholder_text() const¶
Returns the accessible-placeholder-text of that element, if any.
-
inline std::optional<SharedString> accessible_description() const¶
Returns the accessible-description of that element, if any.
-
inline std::optional<float> accessible_value_maximum() const¶
Returns the accessible-value-maximum of that element, if any.
-
inline std::optional<float> accessible_value_minimum() const¶
Returns the accessible-value-minimum of that element, if any.
-
inline std::optional<float> accessible_value_step() const¶
Returns the accessible-value-step of that element, if any.
-
inline std::optional<bool> accessible_checked() const¶
Returns the accessible-checked of that element, if any.
-
inline std::optional<bool> accessible_checkable() const¶
Returns the accessible-checkable of that element, if any.
-
inline std::optional<bool> accessible_item_selected() const¶
Returns the accessible-item-selected of that element, if any.
-
inline std::optional<bool> accessible_item_selectable() const¶
Returns the accessible-item-selectable of that element, if any.
-
inline std::optional<size_t> accessible_item_index() const¶
Returns the accessible-item-index of that element, if any.
-
inline std::optional<size_t> accessible_item_count() const¶
Returns the accessible-item-count of that element, if any.
-
inline std::optional<bool> accessible_expanded() const¶
Returns the accessible-expanded of that element, if any.
-
inline std::optional<bool> accessible_expandable() const¶
Returns the accessible-expandable of that element, if any.
-
inline std::optional<bool> accessible_read_only() const¶
Returns the accessible-read-only of that element, if any.
-
inline void invoke_accessible_expand_action() const¶
Invokes the expand accessibility action of that element (
accessible-action-expand
).
Sets the accessible-value of that element.
Setting the value will invoke the
accessible-action-set-value
callback.
-
inline void invoke_accessible_increment_action() const¶
Invokes the increase accessibility action of that element (
accessible-action-increment
).
-
inline void invoke_accessible_decrement_action() const¶
Invokes the decrease accessibility action of that element (
accessible-action-decrement
).
-
inline void invoke_accessible_default_action() const¶
Invokes the default accessibility action of that element (
accessible-action-default
).
-
inline LogicalSize size() const¶
Returns the size of this element.
-
inline LogicalPosition absolute_position() const¶
Returns the absolute position of this element.
Public Static Functions
-
template<typename T, std::invocable<ElementHandle> Visitor, typename R = std::invoke_result_t<Visitor, ElementHandle>>
static inline auto visit_elements(const ComponentHandle<T> &component, Visitor visitor) -> std::invoke_result_t<Visitor, ElementHandle>¶ Visits visible elements within a component and call the visitor for each of them.
The visitor must be a callable object that accepts an
ElementHandle
and returns eithervoid
, or a type that can be converted tobool
.If the visitor returns
void
, the visitation continues until all elements have been visited.If the visitor returns a type that can be converted to
bool
, the visitation continues as long as the conversion result is false; otherwise, it stops, returning that value. If the visitor never returns something that convertts to true, then the function returns a default constructed value;
auto element = ElementHandle::visit_elements(component, [&](const ElementHandle& eh) -> std::optional<ElementHandle> { return eh.id() == "Foo::bar" ? std::make_optional(eh) : std::nullopt; });
Find all elements matching the given accessible label.
Find all elements matching the given element_id.
Find all elements matching the given type name.
-
inline bool is_valid() const¶