// parent.qml import QtQuick 2.1 import QtQuick.Controls 1.0 Rectangle { width: 640 height: 480 signal closed Button { text: qsTr("Open child window") anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter onClicked: { child.visible = true } } TextField { id: text_field1 x: 93 y: 299 width: 471 height: 22 placeholderText: "Text Field" text: activeFocus ? "I have active focus!" : "I do not have active focus" } Child { id: child visible: false modality: Qt.WindowModal } Button { id: button1 x: 488 y: 397 text: "Close" onClicked: { closed() } } } // Child.qml import QtQuick 2.1 import QtQuick.Controls 1.0 import QtQuick.Window 2.0 Window { width: 500 height: 300 TextField { id: text_field1 x: 73 y: 189 width: 227 height: 22 placeholderText: "Text Field" } Button { id: button1 x: 373 y: 187 text: "OK" onClicked: { close() } } } # example.py import sys from PyQt5 import QtWidgets, QtCore, QtQuick from PyQt5.QtWidgets import QDialog, QWidget def qt5_qml_dir(): import os import subprocess qmldir = subprocess.check_output(["qmake", "-query", "QT_INSTALL_QML"]).strip() if len(qmldir) == 0: raise RuntimeError('Cannot find QT_INSTALL_QML directory, "qmake -query ' + 'QT_INSTALL_QML" returned nothing') if not os.path.exists(qmldir): raise RuntimeError("Directory QT_INSTALL_QML: %s doesn't exist" % qmldir) # On Windows 'qmake -query' uses / as the path separator # so change it to \\. if sys.platform.startswith('win'): import string qmldir = string.replace(qmldir, '/', '\\') return qmldir class FocusTest(QDialog): def __init__(self, parent=None): super(FocusTest, self).__init__(parent) self._parent = parent view = QtQuick.QQuickView() self._view = view view.setResizeMode(QtQuick.QQuickView.SizeViewToRootObject) # add the Qt Quick library path view.engine().addImportPath(qt5_qml_dir()) view.setSource(QtCore.QUrl('parent.qml')) w = QWidget.createWindowContainer(view, self) w.setMinimumSize(view.size()) w.setMaximumSize(view.size()) r = view.rootObject() self._root = r r.closed.connect(self.onClosed) def onClosed(self): self._view.close() self.accept() if __name__=="__main__": app = QtWidgets.QApplication(sys.argv) s = "Test placeholder" label = QtWidgets.QLabel(s, None) label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) label.setWindowTitle(s) label.resize(800, 400) label.show() s = FocusTest(label) s.accepted.connect(label.close) s.open() app.exec_()