Jump to content

QComboBox control


Recommended Posts

Hi, all! At my Qt project I have QComboBox with fixed values. For switch values at AutoIt I try to use CUIAutomation2.au3, but value not changes. Anybody can to show me right way for such task? I solved task for editable ComboBox, but for fixed values I tried different combinations, but without success.

 

Spoiler
#include "CUIAutomation2.au3"

Example_QCombobox()

Func Example_QCombobox()
   FileChangeDir("C:\Users\user\Desktop\TestApp")
   Run("C:\Users\user\Desktop\TestApp\Test.exe")
   Sleep( 1000 )
   ; Create UI Automation object
   Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
   If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
   ConsoleWrite( "$oUIAutomation OK" & @CRLF )

   ; Get Desktop element
   Local $pDesktop, $oDesktop
   $oUIAutomation.GetRootElement( $pDesktop )
   $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
   If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
   ConsoleWrite( "$oDesktop OK" & @CRLF )

   ; --- Find window/control ---

   ConsoleWrite( "--- Find window/control ---" & @CRLF )

   Local $pCondition0
   $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "QComboBox", $pCondition0 )
   If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF )
   ConsoleWrite( "$pCondition0 OK" & @CRLF )

   Local $pComboBox1, $oComboBox1
   $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pComboBox1 )
   $oComboBox1 = ObjCreateInterface( $pComboBox1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
   If Not IsObj( $oComboBox1 ) Then Return ConsoleWrite( "$oComboBox1 ERR" & @CRLF )
   ConsoleWrite( "$oComboBox1 OK" & @CRLF )

   ; --- Value Pattern (action) Object ---

   ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF )

   Local $pValuePattern1, $oValuePattern1
   $oComboBox1.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern1 )
   $oValuePattern1 = ObjCreateInterface( $pValuePattern1, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern )
   If Not IsObj( $oValuePattern1 ) Then Return ConsoleWrite( "$oValuePattern1 ERR" & @CRLF )
   ConsoleWrite( "$oValuePattern1 OK" & @CRLF )

   ; --- Value Pattern (action) Methods ---

   ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF )

   $sValue = "B"
   $oValuePattern1.SetValue($sValue)
   ConsoleWrite( "$oValuePattern1.SetValue()" & @CRLF )

   ; --- Copy element info ---

EndFunc

 

 

Link to comment
Share on other sites

I made a small window myself with 2 QtComboboxes one enabled and one not.

Its not a straightforward setvalue and as an alternative then just setfocus and a sendkeys can do the trick either send the value or send a key down/up

You have to play with different combinations like expand that seems to work/show the list of available choices (both comboboxes will react to expand even if disabled 😉 and show the list with choices and based on that you could send one or more keydown with sendkeys)

As it recognizes the controls itself you can reach it with setfocus and then using regular sendkeys to get to right selection. Apparently its not reacting to setvalue or iaccessible.setvalue (I mainly tried with inspect.exe and assume the spytool as made by @LarsJ will not give different results)

 

 

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...