View Full Version : QColor in QtScript

8th June 2009, 07:45
Hi friends,
I want to send QColor object from script to c++ function.
I have a scene in which there r graphics Item and i have
setItemColor(const QColor &color) as Public Slot in my class which is available in script.
when i give
in script the error is red is undefined.

How can i do.

8th June 2009, 10:25
i dont know QtScript module..

but if it were pure Qt/C++ code then i use Qt::red,

8th June 2009, 12:30
The simple solution:

In your code:

public slot:
void setItemColor(int red, int green, int blue, int alpha);

In Qt script:

scene.setItemColor(255, 0, 0, 0);

The advanced solution:


9th June 2009, 11:53
How can I make QColor available to script or directly use color name (red,green,blue,black.....) as my arguments.

9th June 2009, 15:50
1. Declare function:

void setItemColor(int red, int green, int blue, int alpha);

as a public slot.

2. Make the object available for your script:

engine->globalObject().setProperty("myObject", engine->newQObject(myObject));

3. And use it this way in script:

myObject.setItemColor(255, 0, 0, 0);