Forum Discussion

ebodien's avatar
ebodien
Contributor
12 years ago

Read Qt text color in TestComplete

Greetings:



I am trying to read the color of text displayed by a Qt application using TestComplete and I'm not having much luck.  I've tried multiple auto complete options for the font, palette and style sheet properties of the label and in most cases I recieve an error.

For example:




Set Screen = <NameMapped Label>

Color = Screen.QWidget_palette.QPalette_color

Log.Message("Text color is: " & Color)



Any tips on how to access the color propert of a test string would be appreciated.



  • Hi Eero,


     


    Try using the following code:




    function getColor()


    {


     var lbl = Sys.Process("TextColor").QtObject("TextColorClass").QtObject("label"); 


     var role = lbl.QWidget_foregroundRole();


     var color = lbl.palette.QPalette_color(role);


     Log.Message(color.QColor_value());


    }



  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Eero,


     


    Try using the following code:




    function getColor()


    {


     var lbl = Sys.Process("TextColor").QtObject("TextColorClass").QtObject("label"); 


     var role = lbl.QWidget_foregroundRole();


     var color = lbl.palette.QPalette_color(role);


     Log.Message(color.QColor_value());


    }



  • Hi Tanya,



    Thanks for your help, the code got me on the right track.  I did change from QColor_value() to QColor_name().  QColor_value() was only giving me the R value, but QColor_name() gave me the full value in hex, eg for yellow text _value was logged as 237 whereas _name was logged as #ede574.



    Thanks again.