[Interest] What is Qt.red for in QML?

Rutledge Shawn Shawn.Rutledge at theqtcompany.com
Fri Feb 6 08:43:48 CET 2015


On 6 Feb 2015, at 02:36, Jérôme Godbout <jerome at bodycad.com> wrote:

> Sorry read too fast the original post, try to print it, if the int is 0, I would guess it's an indexer for rgba values of some sort. May be wrong on this not near my computer to test
> 
> 
> 
> On Feb 5, 2015, at 8:29 PM, Ian Monroe <ian at monroe.nu> wrote:
> 
>> On Thu, Feb 5, 2015 at 3:33 PM, Jérôme Godbout <jerome at bodycad.com> wrote:
>> you can use the string version
>> color: 'red'
>> or rgba value
>> color: Qt.rgba(1,0,0,1)
>> 
>> Doesn't answer Jason's question, I assume it is some historical oddity.  

It comes from Qt::GlobalColor, and is an enum intended for usage in C++ when you construct a QColor.  So the value is 7.  It is accessible in QML only because everything from the Qt namespace is made available.  Being able to assign this enum to a value of type QColor in QML would require a little more magic in the QML engine, which is not implemented AFAIK.  I agree it feels a bit awkward to write a symbolic color as a quoted string in QML… it leaves you wondering if it is stored that way.  (It isn’t, though; since any color property in Qt Quick is a QColor, it has to call the QColor constructor taking a QString.  Still, a QString had to be constructed, and then thrown away.  In an interpreted language, this is only a drop in the bucket.)  But specifying Qt.red wouldn’t really feel much better, would it?  It’s still a few extra characters to type, and it’s arbitrary to have it in the Qt namespace as opposed to a Color namespace.




More information about the Interest mailing list