Results 1 to 5 of 5

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

  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)

  4. #3
    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 Re: Casted QGraphicsItem from qml file Won't works fine!

    Thanks MarekR22 for reply
    I've tried that example, just like QGraphicsItem the Object is OK!! but it can't be moved by dragging in the scene.
    It must be a way.. I'm so confused ..


    Added after 28 minutes:


    For more info.: The qml Item will add to the scene, but the problem is that the drag and drop won't work. (When i set flag to QGraphicsItem::ItemisMovable, nothing happens and drag and drop still won't work.
    Plz someone help me
    Last edited by alizadeh91; 25th February 2012 at 17:42.

  5. #4
    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 Re: Casted QGraphicsItem from qml file Won't works fine!

    It's so weired!! No one have evered faced with this kinda problem!?

  6. #5
    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: Casted QGraphicsItem from qml file Won't works fine!

    Please provide a minimal compilable example reproducing the problem.
    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.


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.