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.
Code:
void MyWidget::handleButton()
{
QQuickView *view = new QQuickView();
container->setMinimumSize(200, 200);
container->setMaximumSize(200, 200);
container->setFocusPolicy(Qt::TabFocus);
view
->setSource
(QUrl("qrc:/main.qml"));
verticalLayout->addWidget(container);
}
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.
Re: ApplicationWindow inside C++ childwindow (not new window)
If I do
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
What could I do to have the white box contain the content of main.qml?
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().
Re: ApplicationWindow inside C++ childwindow (not new window)
Code:
qDebug() << "status: " << view->status();
is giving me
Code:
status: QQuickView::Status(Error)
I do not know how to print a errors() list. Can you tell me that first?
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,
_
Re: ApplicationWindow inside C++ childwindow (not new window)
Having Item{} as qml rootitem works. But I also have a
in main.qml. How to show these buttons using QQuickView?
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,
_
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?
Re: ApplicationWindow inside C++ childwindow (not new window)
What's the content item of you "ApplicationWindow" element?
Cheers,
_
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?
Re: ApplicationWindow inside C++ childwindow (not new window)
Quote:
Originally Posted by
bchinfosieeuw
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.
Code:
import QtQuick 2.0
Rectangle {
width: 100
height: 100
color: "blue"
}
Cheers,
_