Results 1 to 3 of 3

Thread: QDeclarativeItem not changing colors when event is fired in QML

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDeclarativeItem not changing colors when event is fired in QML

    Hi,

    I defined a QML file that changes the color of a mousearea's parent when it is clicked (based off of the sample from the documentation). For some reason, the color change that is suppose to happen never happens. The application that I am creating is not a pure QML app (works in that scenario). Instead, I have a qt application with a qgraphicsscene. I am loading the qml as a QdeclarativeItem and adding it into the scene. Does anyone know what I am doing wrong?

    Thanks.

    QT code:
    Qt Code:
    1. QDeclarativeEngine engine;
    2.  
    3. QDeclarativeComponent component(&engine, QUrl("qrc:/qml/test.qml"));
    4.  
    5. QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(component.create());
    6.  
    7. qDebug() << component.errors();
    8. test->addItem(item);
    9. designWidget.graphicsView->setScene(test);
    To copy to clipboard, switch view to plain text mode 

    QML:

    import QtQuick 1.0


    javascript Code:
    1. Rectangle {
    2. id: container
    3. width: 600; height: 200
    4.  
    5. Rectangle {
    6. id: rect
    7. width: 50; height: 50
    8. color: "red"
    9. opacity: (600.0 - rect.x) / 600
    10.  
    11. MouseArea {
    12. anchors.fill: parent
    13. drag.target: rect
    14. drag.axis: Drag.XandYAxis
    15. drag.minimumX: 0
    16. drag.maximumX: container.width - rect.width
    17. drag.minimumY: 0
    18. drag.maximumY: container.height - rect.height
    19.  
    20. acceptedButtons: Qt.LeftButton | Qt.RightButton
    21. onClicked: {
    22. parent.color = "blue"
    23. }
    24.  
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 28th February 2011 at 00:22.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDeclarativeItem not changing colors when event is fired in QML

    Doesn't the engine go out of scope when you leave the method?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    hkenn124 (27th February 2011)

  4. #3
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDeclarativeItem not changing colors when event is fired in QML

    Thanks. That was it. I really am a newb I guess that is what I get for cutting and pasting.

    Thanks Again!

Similar Threads

  1. Using a QML model from a QDeclarativeItem subclass
    By humbleguru in forum Qt Programming
    Replies: 1
    Last Post: 3rd January 2011, 12:07
  2. Changing form colors and adding skins
    By srohit24 in forum Qt Programming
    Replies: 9
    Last Post: 28th October 2009, 15:35
  3. Changing colors and textures?
    By Dumbledore in forum Qt Tools
    Replies: 3
    Last Post: 12th October 2007, 18:18
  4. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  5. Changing Progress Bar Colors
    By bpetty in forum Newbie
    Replies: 1
    Last Post: 11th August 2006, 17:29

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.