PDA

View Full Version : QColor in QtScript



Kingofhearts_sri
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
scene.setItemColor(red)
in script the error is red is undefined.

How can i do.

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

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

bunjee
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:

http://doc.trolltech.com/4.5/qtscript.html#implementing-prototype-objects-for-value-based-types

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

bunjee
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);