Results 1 to 4 of 4

Thread: setparent/setparentitem for window

  1. #1
    Join Date
    Nov 2020
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default setparent/setparentitem for window

    Hi,

    I have a window, then I create a new window and want to show it within the first window(with showing title window/minimize window, and it should be movable only within the first window). But set parent does not work.

    Qt Code:
    1. QQmlApplicationEngine engine;
    2. QQmlComponent component(&engine, QUrl("qrc:/main.qml"));
    3.  
    4. QObject *m_visual = component.create();
    5. QQuickWindow *window = (QQuickWindow *)m_visual;
    6.  
    7.  
    8.  
    9. QQmlApplicationEngine engine_sub;
    10. QQmlComponent component_sub(&engine_sub, QUrl("qrc:/window2.qml"));
    11.  
    12. QObject *m_visual_sub = component_sub.create();
    13.  
    14.  
    15.  
    16. QQuickWindow *window_sub = (QQuickWindow *)m_visual_sub;
    17. m_visual_sub->setParent(m_visual);
    18. ((QQuickItem *)m_visual_sub)->setParentItem(window->contentItem());
    To copy to clipboard, switch view to plain text mode 


    Thank you so much!

  2. #2
    Join Date
    Dec 2020
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: setparent/setparentitem for window

    Hi,

    I have a window, then I create a new window and want to show it within the first window(with showing title window/minimize window, and it should be movable only within the first window). But set parent does not work.

    Qt Code:
    1. QQmlApplicationEngine engine;
    2. QQmlComponent component(&engine, QUrl("qrc:/main.qml"));
    3.  
    4. QObject *m_visual = component.create();
    5. QQuickWindow *window = (QQuickWindow *)m_visual;
    6.  
    7.  
    8.  
    9. QQmlApplicationEngine engine_sub;
    10. QQmlComponent component_sub(&engine_sub, QUrl("qrc:/window2.qml"));
    11.  
    12. QObject *m_visual_sub = component_sub.create();
    13.  
    14.  
    15.  
    16. QQuickWindow *window_sub = (QQuickWindow *)m_visual_sub;
    17. m_visual_sub->setParent(m_visual);
    18. ((QQuickItem *)m_visual_sub)->setParentItem(window->contentItem());
    To copy to clipboard, switch view to plain text mode 


    Thank you so much!
    any update
    got stuck in the same place
    Great tips on how to write amazing assignment you will find at https://justdomyhomework.com/

  3. #3
    Join Date
    Feb 2021
    Location
    Minneapolis MN USA
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: setparent/setparentitem for window

    The owner can be set, but the parent is a read-only property.

    Qt Code:
    1. var w = new Window ();
    2. w.Owner = Window.GetWindow (this);
    3. w.Show ();
    To copy to clipboard, switch view to plain text mode 
    Last edited by Gary_Elliott; 26th February 2021 at 18:08. Reason: code display correction

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,249
    Thanks
    304
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setparent/setparentitem for window

    var w = new Window ();
    w.Owner = Window.GetWindow (this);
    w.Show ();
    What is this? It isn't Qt code. It isn't even C++, it's C#. So why are you posting this in a Qt forum?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. SetParent(0) : SetMaximized() vs SetFullScreen()
    By antweb in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2015, 10:30
  2. Cant use QWidget::setParent().
    By vitaR in forum Newbie
    Replies: 2
    Last Post: 2nd July 2014, 02:48
  3. QObject::setParent across threads.
    By psih128 in forum Qt Programming
    Replies: 4
    Last Post: 21st January 2014, 17:01
  4. Replies: 2
    Last Post: 12th June 2009, 11:55
  5. Qt widget setParent
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 30th November 2007, 21:38

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.