Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing "parent"-property of GraphicsItem fails

Accessing "parent"-property of GraphicsItem fails

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 890 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    André Bergner
    wrote on last edited by
    #1

    I'm having a hard time figuring out, how to use the property-(s/g)etters to change the parentItem of a QGraphicsObject or QDeclarativeItem.

    The following little program will make my point:
    @
    #include <QApplication>
    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QGraphicsWidget>
    #include <QDeclarativeEngine>
    #include <QDeclarativeComponent>
    #include <QDeclarativeItem>
    #include <QDebug>

    int main( int argNum , char** arg )
    {
    QApplication app( argNum , arg );
    QGraphicsScene scene( QRectF(0,0,200,200) );
    QGraphicsWidget* rootItem = new QGraphicsWidget;

    QDeclarativeEngine engine;
    QDeclarativeComponent qml( &engine );
    qml.setData( "import QtQuick 1.1; Rectangle { width: 100; height: 100; color:'red' }", QUrl() );
    QGraphicsObject* qmlItem = qobject_cast<QGraphicsObject*>(qml.create());
    qmlItem->setParentItem( rootItem );
    // NEITHER OF THE FOLLOWING LINES DO WORK
    //qmlItem->setProperty( "parent", QVariant::fromValue(qobject_cast<QObject*>(rootItem)) );
    //qmlItem->setProperty( "parent", QVariant::fromValue(qobject_cast<QGraphicsItem*>(rootItem)) );
    //qmlItem->setProperty( "parent", QVariant::fromValue(qobject_cast<QGraphicsObject*>(rootItem)) );
    //qmlItem->setProperty( "parent", QVariant::fromValue(qobject_cast<QDeclarativeItem*>(rootItem)) );

    scene.addItem( rootItem );
    QGraphicsView view( &scene );
    view.show();
    return app.exec();
    }
    @

    As noted in the source, setting the parent item of qmlItem directly works as expected. But trying to set via the parent property does not work in any of the version I tried above.

    What am I'm doing wrong?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved