Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.9.1, 5.10.1, 5.11.1, 5.12.4, 5.13.0
-
None
-
Qt 5.9.1 : MinGW32
Qt 5.10.1 : MinGW32
Qt 5.11.1 : MinGW32
Qt 5.12.1 : MinGW32
Qt 5.13.1 : MinGW32
Description
// main.cpp #include <QtQml/QQmlApplicationEngine> #include <QtWidgets/QApplication> #include <QtQuick/QQuickWindow> #include <QtWidgets> int main(int argc, char *argv[]) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); QWindow *qmlWindow = qobject_cast<QWindow*>(engine.rootObjects().at(0)); QWidget *container = QWidget::createWindowContainer(qmlWindow); container->setMinimumSize(qmlWindow->size()); QWidget *widget = new QWidget(); QGridLayout *grid = new QGridLayout(widget); grid->addWidget(container,0,0); grid->addWidget(new QPushButton(widget),1,0); widget->show(); return app.exec(); }
// main.qml import QtQuick 2.0 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.2 import QtQuick.Controls.Material 2.1 import QtQuick.Controls.Universal 2.1 import Qt.labs.settings 1.0 ApplicationWindow { visible:true color:"blue" header: ToolBar { RowLayout { anchors.fill: parent ToolButton { text: qsTr("‹") onClicked: stack.pop() } Label { text: "Title" elide: Label.ElideRight horizontalAlignment: Qt.AlignHCenter verticalAlignment: Qt.AlignVCenter Layout.fillWidth: true } ToolButton { text: qsTr("⋮") onClicked: menu.open() } } } StackView { id: stack anchors.fill: parent } }
I don't know this problem it's about
QQmlApplicationEngine
or
QWidget::createWindowContainer
.
I want to embed QML into QMainWindow. When I run the main.cpp , the QML will Interface drift in QMainWindow's layout like as error1.gif and error2.gif.
( 我想把QML界面嵌入到QMainWindow 中 , 但是会发生附件 error1.gif 和 error2.gif 中的错误, 我不知道是QQmlApplicationEngine 的问题还是 QWidget::createWindowContainer 的问题)
Attachments
Issue Links
- is duplicated by
-
QTBUG-80925 QWidget::createWindowContainer Interface drift
- Closed
- is required for
-
QTBUG-45275 Wrong display with foreign widget with QWidget::createWindowContainer()
- Closed