Jump to content

Select item in a QT combo box


LaurentR
 Share

Recommended Posts

Hi everybody,

I try to select an item in a qt combo box.

With UIASpy : I have a QCombox (type $UIA_ComboBoxControlTypeId) with a List QComboBoxListView (type $UIA_ListControlTypeId) and several item of ListItem (type $UIA_ListItemControlTypeId). 

I wrote a function to select an item, but it's note working. can you help me. thanks in advance

 

Func qtAutoitComboBox_SetVal($oDialog,$aValue)
    if _UIA_IsElement($oDialog) then
        ; _UIA_action($oDialog,"leftclick")
        local $ssearch="ControlType:=UIA_ListControlTypeId;class:=QComboBoxListView"
        local $oDialogChild=_UIA_getObjectByFindAll($oDialog,$ssearch, $treescope_subtree)
        if _UIA_IsElement($oDialogChild) then
            Local $pElements
            Local $oAutomationElementArray
            Local $iLength
            $oDialogChild.FindAll($treescope_subtree, $UIA_oTRUECondition, $pElements)
            $oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
            If _UIA_IsElement($oAutomationElementArray) Then
                $oAutomationElementArray.Length($iLength)
                For $i = 0 To $iLength-1 Step 1
                    Local $oElement
                    Local $pElement
                    $oAutomationElementArray.GetElement($i, $oElement)
                    $pElement = ObjCreateInterface($oElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
                    _GUICtrlComboBox_SetCurSel($oDialogChild,5)
                    If _UIA_IsElement($pElement) AND _UIA_getPropertyValue($pElement, $UIA_ClassNamePropertyId) <> "QComboBoxListView" Then
                        Local $pSelectionItemPattern, $oSelectionItemPattern
                        $pElement.GetCurrentPattern( $UIA_SelectionItemPatternId, $pSelectionItemPattern )
                        $oSelectionItemPattern = ObjCreateInterface( $pSelectionItemPattern, $sIID_IUIAutomationSelectionItemPattern, $dtagIUIAutomationSelectionItemPattern )
                        If _UIA_IsElement( $oSelectionItemPattern ) Then
                            if _ArraySearch($aValue,_UIA_getPropertyValue($pElement, $UIA_NamePropertyId)) <> -1 then
                                $oSelectionItemPattern.Select()
                            else
                                $oSelectionItemPattern.RemoveFromSelection()
                            endif
                        endif
                    endif
                Next
            endif
        endif
    endif
EndFunc   ;==>qtAutoitComboBox_SetVal
 

Link to comment
Share on other sites

Yes I got for the QComboBoxListView 

Control Patterns (element actions)                  
$UIA_IsLegacyIAccessiblePatternAvailablePropertyId  True (LegacyIAccessiblePattern)
$UIA_IsSelectionPatternAvailablePropertyId          True (SelectionPattern)
$UIA_IsValuePatternAvailablePropertyId              True (ValuePattern)
 

and for the item ListItem 

Control Patterns (element actions)                  
$UIA_IsInvokePatternAvailablePropertyId             True (InvokePattern)
$UIA_IsLegacyIAccessiblePatternAvailablePropertyId  True (LegacyIAccessiblePattern)
$UIA_IsSelectionItemPatternAvailablePropertyId      True (SelectionItemPattern)
$UIA_IsValuePatternAvailablePropertyId              True (ValuePattern)
 

 

 

Link to comment
Share on other sites

I am not sure if in UIASpy you have the option to trigger the event to see if it works at all

  • Try inspect.exe it has an option to execute patterns if they exist so you can see if the selection pattern in itself works (QT Widgets do have not all support in a proper way)
  • _GUICtrlComboBox_SetCurSel($oDialogChild,5) in general do not mix UIA and AutoIt functions
  • Is your element of interest found by your code, to make sure add a highlight element or consolewrite of some properties so you can debug

https://doc.qt.io/qt-5/accessible-qwidget.html gives an indication on how QT has done things with accessibility

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...