PDA

View Full Version : ApplicationWindow inside C++ childwindow (not new window)



bchinfosieeuw
3rd January 2017, 11:52
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.



void MyWidget::handleButton()
{

QQuickView *view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(view, this);
container->setMinimumSize(200, 200);
container->setMaximumSize(200, 200);
container->setFocusPolicy(Qt::TabFocus);
view->setSource(QUrl("qrc:/main.qml"));
QVBoxLayout *verticalLayout = new QVBoxLayout();
verticalLayout->addWidget(container);

}

d_stranz
3rd January 2017, 21:16
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.

bchinfosieeuw
3rd January 2017, 22:58
If I do


QVBoxLayout *verticalLayout = new QVBoxLayout(this);

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


container->show();

What could I do to have the white box contain the content of main.qml?

d_stranz
3rd January 2017, 23:12
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().

bchinfosieeuw
4th January 2017, 11:49
qDebug() << "status: " << view->status();


is giving me



status: QQuickView::Status(Error)


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

anda_skoa
4th January 2017, 14:35
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,
_

bchinfosieeuw
4th January 2017, 15:54
Having Item{} as qml rootitem works. But I also have a


toolBar:ToolBar {


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

anda_skoa
4th January 2017, 18:16
ToolBar is just a normal element type, you can also position it in your item using anchors.

Cheers,
_

bchinfosieeuw
4th January 2017, 21:35
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?

anda_skoa
5th January 2017, 09:49
What's the content item of you "ApplicationWindow" element?

Cheers,
_

bchinfosieeuw
5th January 2017, 13:51
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?

anda_skoa
6th January 2017, 09:50
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.



import QtQuick 2.0

Rectangle {
width: 100
height: 100

color: "blue"
}


Cheers,
_