Results 1 to 5 of 5

Thread: Casted QGraphicsItem from qml file Won't works fine!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Casted QGraphicsItem from qml file Won't works fine!

    Hello everybody..
    I've a question about QGraphicsItem.
    I've casted a qml file to QGraphicsItem (by creating a object by engine). And it's OK . But when i add this QGraphicsItem into a scene and view and i set its flag to be movable nothing will do when i try to drag it.
    Here is the code:

    QDeclarativeEngine engine;
    QDeclarativeComponent component(&engine,QUrl::fromLocalFile("qml/TabbedPage/Dial.qml"));

    QObject *object = component.create();

    QGraphicsItem *newItem = qobject_cast<QGraphicsItem *>(object);
    newItem->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
    newItem->setAcceptsHoverEvents(true);
    newItem->setAcceptedMouseButtons(Qt::LeftButton);
    scene.addItem(newItem);
    view.setScene(&scene);
    view.show();

    What's the problem? !

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Casted QGraphicsItem from qml file Won't works fine!

    Try cast to QDeclarativeItem* like in exmple.

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

    alizadeh91 (25th February 2012)

Similar Threads

  1. Replies: 15
    Last Post: 8th June 2013, 06:15
  2. Replies: 7
    Last Post: 13th September 2011, 14:39
  3. Replies: 1
    Last Post: 31st December 2010, 16:35
  4. Replies: 3
    Last Post: 11th December 2009, 17:13
  5. update() works fine sometime but not everytime..!!
    By salmanmanekia in forum Qt Programming
    Replies: 19
    Last Post: 22nd August 2008, 09:11

Tags for this Thread

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.