Results 1 to 3 of 3

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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.