Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. What is the best way to create new QQuickItem on C++ side with the same properties as an existing one
Qt 6.11 is out! See what's new in the release blog

What is the best way to create new QQuickItem on C++ side with the same properties as an existing one

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 708 Views
  • 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.
  • Roby BrundleR Offline
    Roby BrundleR Offline
    Roby Brundle
    wrote on last edited by
    #1

    I have a QQuickItem fetched from C++ side like this.

    QQuickItem * my_item = qmlEngine->rootObjects()[0]->findChild<QQuickItem*>("ItemObjectName");
    

    my_item is valid & has all the properties set on to it.

    Scenario
    I have 2 windows which need this QQuickItem to be drawn on alterantively. I want to render this my_item to a different window. This works perfectly fine as long as I set the Parent of the my_item to the other window

    // the_other_window is a QQuickWindow
    QQuickWindow * the_other_window;
    
    // here I set parent
    my_item->setParentItem(the_other_window->contentItem());
    

    This requires me to do setParentItem again back to my_item's original window otherwise it goes invisible on the original window. This is working but gives me unnecessary dependency. Instead I am trying to create a copy of the QQuickItem & do a setParentItem on that. By copying like this:

    QQuickItem * item_copy = new QQuickItem(my_item);
    

    I want to make item_copy as exactly the same as my_item. I learnt that QQuickItem is not copyable. So, want to set all properties of my_item into item_copy. Thus recreating my_item from scratch. How can I do this? What properties should I copy primarily? width, height, x, y & what else?
    Is there a method to copy all the valid properties into this new one without copying each one by one?

    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