Results 1 to 5 of 5

Thread: QColor in QtScript

  1. #1
    Join Date
    Jan 2009
    Posts
    12
    Qt products
    Qt4

    Default QColor in QtScript

    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
    Qt Code:
    1. scene.setItemColor(red)
    To copy to clipboard, switch view to plain text mode 
    in script the error is red is undefined.

    How can i do.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QColor in QtScript

    i dont know QtScript module..

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

  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QColor in QtScript

    The simple solution:

    In your code:
    Qt Code:
    1. public slot:
    2. void setItemColor(int red, int green, int blue, int alpha);
    To copy to clipboard, switch view to plain text mode 

    In Qt script:
    Qt Code:
    1. scene.setItemColor(255, 0, 0, 0);
    To copy to clipboard, switch view to plain text mode 

    The advanced solution:

    http://doc.trolltech.com/4.5/qtscrip...ue-based-types

  4. #4
    Join Date
    Jan 2009
    Posts
    12
    Qt products
    Qt4

    Default Re: QColor in QtScript

    How can I make QColor available to script or directly use color name (red,green,blue,black.....) as my arguments.

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QColor in QtScript

    1. Declare function:

    Qt Code:
    1. void setItemColor(int red, int green, int blue, int alpha);
    To copy to clipboard, switch view to plain text mode 

    as a public slot.

    2. Make the object available for your script:

    Qt Code:
    1. engine->globalObject().setProperty("myObject", engine->newQObject(myObject));
    To copy to clipboard, switch view to plain text mode 

    3. And use it this way in script:

    Qt Code:
    1. myObject.setItemColor(255, 0, 0, 0);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QtScript basic tutorial
    By thomir in forum Qt Programming
    Replies: 2
    Last Post: 2nd April 2013, 04:17
  2. QtScript Binding problem with QWidget
    By zack in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 09:38
  3. Using enums in QtScript
    By Orphelic in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2007, 11:55
  4. QtScript Q_ENUM problem
    By oc2k1 in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2007, 16:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.