Results 1 to 12 of 12

Thread: ApplicationWindow inside C++ childwindow (not new window)

  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default ApplicationWindow inside C++ childwindow (not new window)

    I have the following code inside a method handleButton(), which gives me the qml ApplicationWindow inside a new window when handleButton() is triggered. But how can I place the content of the ApplicationWindow inside the C++ childwindow (shown with help of MyWidget)? For example, if I say mainLayout->addLayout(verticalLayout);
    then there comes a white area inside the GroupBox in which handleButton is triggered. But I want to have this white area in the child window, and it must not be a white area: it must contain the qml ApplicationWindow. Any help appreciated.

    Qt Code:
    1. void MyWidget::handleButton()
    2. {
    3.  
    4. QQuickView *view = new QQuickView();
    5. QWidget *container = QWidget::createWindowContainer(view, this);
    6. container->setMinimumSize(200, 200);
    7. container->setMaximumSize(200, 200);
    8. container->setFocusPolicy(Qt::TabFocus);
    9. view->setSource(QUrl("qrc:/main.qml"));
    10. QVBoxLayout *verticalLayout = new QVBoxLayout();
    11. verticalLayout->addWidget(container);
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    In Line 5 you are creating a QWidget as a container, but you tell it that "MyWidget" is its parent ("this"). Then in Line 10, you create a QVBoxLayout with no parent and add the widget to that.

    So what you are doing is telling MyWidget that "Here's a new child widget, but I won't tell you where to place it on screen. I've put it into a layout, but I won't tell you about that either. Oh, and I'm not going to call container->show() so it will just be a white square."

    If you want the "childwindow" (whatever that is) to be visible independently of MyWidget, then don't make MyWidget the parent. If you want the container to be laid out properly in "childwindow", then you need to add the layout to it. And you need to call "show()" on the container so it becomes visible.
    <=== 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.

  3. #3
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    If I do
    Qt Code:
    1. QVBoxLayout *verticalLayout = new QVBoxLayout(this);
    To copy to clipboard, switch view to plain text mode 
    I get a white box in the right place. But this box must contain the contents of main.qml. Now it is still making a new window of it, even if I use
    Qt Code:
    1. container->show();
    To copy to clipboard, switch view to plain text mode 
    What could I do to have the white box contain the content of main.qml?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    1 - Are you sure the URL is correct? What is the return value from QQuickView::status()?

    2 - You may also need to call view->show() in addition to container->show().
    <=== 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.

  5. #5
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    Qt Code:
    1. qDebug() << "status: " << view->status();
    To copy to clipboard, switch view to plain text mode 

    is giving me

    Qt Code:
    1. status: QQuickView::Status(Error)
    To copy to clipboard, switch view to plain text mode 

    I do not know how to print a errors() list. Can you tell me that first?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    Obviously your root QML element should also not be a Window type, as that is explicitly for creating a stand alone window.

    Btw, there is also QQuickWidget.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    Having Item{} as qml rootitem works. But I also have a
    Qt Code:
    1. toolBar:ToolBar {
    To copy to clipboard, switch view to plain text mode 

    in main.qml. How to show these buttons using QQuickView?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    ToolBar is just a normal element type, you can also position it in your item using anchors.

    Cheers,
    _

  9. #9
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    Inside the root Item{} I cannot even show a regular Button. It is not clear to me how to do it. Can you explain a little bit more?

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    What's the content item of you "ApplicationWindow" element?

    Cheers,
    _

  11. #11
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    My ApplicationWindow {} did not have a contentItem, but it is Item {} now, and "contentItem:" is a non-existent property of Item {}. So how to show a Button?

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: ApplicationWindow inside C++ childwindow (not new window)

    Quote Originally Posted by bchinfosieeuw View Post
    My ApplicationWindow {} did not have a contentItem
    Ok, so you had an empty window with just the ToolBar, I though that you maybe already had some content in your window.

    In QtQuick, to show something you only need to instantiate it, potentially provide values for size if it doesn't have an implicit one.

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. width: 100
    5. height: 100
    6.  
    7. color: "blue"
    8. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 24th November 2016, 14:13
  2. How run Windows QProcess Window inside QWidget
    By aguayro in forum Qt Programming
    Replies: 6
    Last Post: 25th June 2015, 09:53
  3. Replies: 3
    Last Post: 10th February 2014, 19:46
  4. Open a window inside another window
    By passerb in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2009, 14:24
  5. How to embed coin widget inside qt window?
    By jwieland in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 16:50

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.