If condition on a color property
-
-
Hi Volker,
[quote author="Volker" date="1295601142"]
I'm not a QML expert, I would try something like this:@
if(parent.color == QColor("black"))
@
[/quote]i've tried before, but got the following in the console:
@
Mouse clicked! #000000
file:///home/jventura/workspace/QtTests/QML/view.qml:19: ReferenceError: Can't find variable: QColor
@I think JavaScript also doesn't know about internal Qt types (at least in this way without "registering" or that kind of things which I still didn't explore yet)..
I also tried things like color.black, etc., but i think only things like '#000000' work..But no problem, this is only a simple thing and can be circunvented. With was just to make the point that sometimes the users find little details that the framework developers didn't thought it would be used that way..
Thank you all,
João Ventura -
Seems that does not work at the moment - see "QTBUG-14731":http://bugreports.qt.nokia.com/browse/QTBUG-14731
-
[quote author="Volker" date="1295611584"]Seems that does not work at the moment - see "QTBUG-14731":http://bugreports.qt.nokia.com/browse/QTBUG-14731[/quote]
Hi Volker, seems the answer to your suggestion, but not the answer to the original supposition, although it may serve. As i said, i don't know if the @if (parent.color == 'black')@ not working as intuitive is an error or a language design decison, so i will leave that for the experts..
Thanks for your feedback,
João Ventura -
The color 'black' is just an alias for '#000000', so internally it is converted to the latter. That's why your comparison with 'black' fails. Unfortunately there seems to be no way to convert 'black' to '#000000' on the fly to enable the proper comparison.
-
I had the same problem. I've tried many, many different approaches, but the only one that works is this:
if (parent.color != Qt.rgba(0, 0, 0, 1)) parent.color = "black"; else parent.color = "blue";
For some bizarre reason, these always evaluate to false:
if (parent.color == Qt.rgba(0, 0, 0, 1))
if (parent.color === Qt.rgba(0, 0, 0, 1))It's the same exact comparison, but for equality.
-
Sorry about the formatting; I'm having trouble with colors and indentation...
-
This looks a little better. Still can't get indent to work, though...
I had the same problem. I’ve tried many, many different approaches, but the only one that works is this:
[color=red]if[/color] (parent.color != [color=blue]Qt[/color].rgba(0, 0, 0, 1)) parent.color = “black”;
[color=red]else[/color] parent.color = “blue”;For some bizarre reason, these always evaluate to false:
[color=red]if[/color] (parent.color [color=blue]Qt[/color].rgba(0, 0, 0, 1))
[color=red]if[/color] (parent.color = [color=blue]Qt[/color].rgba(0, 0, 0, 1))It’s the same exact comparison, but for equality.
-
When I posted the above, some characters were removed.
There should be a double and then a triple equal sign between compared colors like so:
[color=red]if[/color] (parent.color == [color=blue]Qt[/color].rgba(0, 0, 0, 1))
[color=red]if[/color] (parent.color === [color=blue]Qt[/color].rgba(0, 0, 0, 1))
-
I did more experimenting on this. It turns out that white is the only color this comparison works on. Both of these work fine:
[color=red]if[/color](parent.color != [color=blue]Qt[/color].rgba(255, 255, 255, 1) )
[color=red]if[/color](parent.color == [color=blue]Qt[/color].rgba(255, 255, 255, 1) )
But any other color either evaluates false for every comparison or true for every comparison, depending on if the test is for equality or inequality. I messed with opacity values - didn't help.
Weird.
-
I'm new to QT development and have started playing around with some simple programs using latest QT 5.7.
This issue is still seen in my latest setup.
Snapshot of the QT Setup Used from the "About Panel"
Qt Creator 4.0.3
Based on Qt 5.7.0 (Clang 7.0 (Apple), 64 bit)
Built on Jul 5 2016 01:07:01 -
@SJ_Arjun
use the colorEqual method