QDialog中嵌入qml窗体并缩放
This commit is contained in:
parent
001b56683b
commit
d349e1811e
10 changed files with 256 additions and 0 deletions
Binary file not shown.
After Width: | Height: | Size: 812 KiB |
|
@ -0,0 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'D:\QGroup_432987409\WoHowLearn\0.M_I_pyqt\partner_625781186\QML_QtQuick_PY\QDialog中嵌入qml窗体并缩放\py_qml.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.9.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.resize(420, 317)
|
||||
Dialog.setSizeGripEnabled(True)
|
||||
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.widget = QtWidgets.QWidget(Dialog)
|
||||
self.widget.setObjectName("widget")
|
||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.widget)
|
||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||
self.pushButton = QtWidgets.QPushButton(self.widget)
|
||||
self.pushButton.setObjectName("pushButton")
|
||||
self.verticalLayout_2.addWidget(self.pushButton)
|
||||
self.widget_2 = QtWidgets.QWidget(self.widget)
|
||||
self.widget_2.setStyleSheet("background-color: rgb(85, 255, 127);")
|
||||
self.widget_2.setObjectName("widget_2")
|
||||
self.verticalLayout_2.addWidget(self.widget_2)
|
||||
self.verticalLayout.addWidget(self.widget)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
|
||||
self.pushButton.setText(_translate("Dialog", "PushButton"))
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
Dialog = QtWidgets.QDialog()
|
||||
ui = Ui_Dialog()
|
||||
ui.setupUi(Dialog)
|
||||
Dialog.show()
|
||||
sys.exit(app.exec_())
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
||||
<!-- eric6 user project file for project py_qml -->
|
||||
<!-- Saved: 2018-04-16, 21:51:59 -->
|
||||
<!-- Copyright (C) 2018 , -->
|
||||
<UserProject version="4.0"/>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Tasks SYSTEM "Tasks-6.0.dtd">
|
||||
<!-- eric6 tasks file for project py_qml -->
|
||||
<!-- Saved: 2018-04-16, 21:51:59 -->
|
||||
<Tasks version="6.0">
|
||||
<ProjectScanFilter></ProjectScanFilter>
|
||||
</Tasks>
|
|
@ -0,0 +1,63 @@
|
|||
import QtQuick 2.8
|
||||
import QtQuick.Window 2.2
|
||||
import QtQuick.Controls 2.2
|
||||
import QtQuick.Controls.Material 2.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
Rectangle {
|
||||
id: rectangle
|
||||
visible: true
|
||||
width: 300
|
||||
height: 300
|
||||
|
||||
color: "#0e0c0c"
|
||||
clip: false
|
||||
|
||||
GridLayout {
|
||||
anchors.leftMargin: 0
|
||||
anchors.topMargin: 0
|
||||
anchors.rightMargin: 107
|
||||
anchors.bottomMargin: 0
|
||||
anchors.fill: parent
|
||||
rows: 3
|
||||
columns: 2
|
||||
|
||||
Slider {
|
||||
id: slider
|
||||
Layout.columnSpan: 2
|
||||
value: 0.5
|
||||
}
|
||||
|
||||
Switch {
|
||||
id: switch1
|
||||
text: qsTr("Switch")
|
||||
Layout.columnSpan: 2
|
||||
}
|
||||
|
||||
ProgressBar {
|
||||
id: progressBar
|
||||
Layout.columnSpan: 2
|
||||
value: 0.5
|
||||
}
|
||||
|
||||
RadioButton {
|
||||
id: radioButton
|
||||
text: qsTr("Radio Button")
|
||||
checked: true
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: rectangle1
|
||||
x: 183
|
||||
y: -86
|
||||
width: 200
|
||||
height: 100
|
||||
color: "#514e4e"
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: -80
|
||||
anchors.bottom: parent.top
|
||||
anchors.bottomMargin: 0
|
||||
rotation: 45
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
|
||||
<!-- eric project file for project py_qml -->
|
||||
<!-- Saved: 2018-04-16, 21:43:34 -->
|
||||
<!-- Copyright (C) 2018 , -->
|
||||
<Project version="5.1">
|
||||
<Language>en_US</Language>
|
||||
<Hash>f9e9b523848f67179e680306c360ec26235c78df</Hash>
|
||||
<ProgLanguage mixed="0">Python3</ProgLanguage>
|
||||
<ProjectType>PyQt5</ProjectType>
|
||||
<Version>0.1</Version>
|
||||
<Author></Author>
|
||||
<Email></Email>
|
||||
<Eol index="0"/>
|
||||
<Sources>
|
||||
<Source>Ui_py_qml.py</Source>
|
||||
<Source>py_qml.py</Source>
|
||||
</Sources>
|
||||
<Forms>
|
||||
<Form>py_qml.ui</Form>
|
||||
</Forms>
|
||||
<Translations/>
|
||||
<Resources/>
|
||||
<Interfaces/>
|
||||
<Others/>
|
||||
<Vcs>
|
||||
<VcsType>None</VcsType>
|
||||
</Vcs>
|
||||
<FiletypeAssociations>
|
||||
<FiletypeAssociation pattern="*.e4p" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES"/>
|
||||
<FiletypeAssociation pattern="*.md" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="*.py" type="SOURCES"/>
|
||||
<FiletypeAssociation pattern="*.py3" type="SOURCES"/>
|
||||
<FiletypeAssociation pattern="*.pyw" type="SOURCES"/>
|
||||
<FiletypeAssociation pattern="*.pyw3" type="SOURCES"/>
|
||||
<FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/>
|
||||
<FiletypeAssociation pattern="*.qrc" type="RESOURCES"/>
|
||||
<FiletypeAssociation pattern="*.rst" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/>
|
||||
<FiletypeAssociation pattern="*.txt" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="*.ui" type="FORMS"/>
|
||||
<FiletypeAssociation pattern="README" type="OTHERS"/>
|
||||
<FiletypeAssociation pattern="README.*" type="OTHERS"/>
|
||||
</FiletypeAssociations>
|
||||
</Project>
|
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Module implementing Dialog.
|
||||
"""
|
||||
from PyQt5 import QtGui, QtWidgets, QtCore
|
||||
from PyQt5.QtCore import *
|
||||
from PyQt5.QtGui import *
|
||||
from PyQt5.QtWidgets import *
|
||||
from PyQt5.QtQuickWidgets import *
|
||||
|
||||
from Ui_py_qml import Ui_Dialog
|
||||
|
||||
|
||||
class Dialog(QDialog, Ui_Dialog):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
|
||||
super(Dialog, self).__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.m_quickWidget=QQuickWidget();
|
||||
self.m_quickWidget.setResizeMode(QQuickWidget.SizeRootObjectToView) ;
|
||||
self.m_quickWidget.setSource(QUrl("py_mqltest.qml"));
|
||||
self.verticalLayout.addWidget(self.m_quickWidget)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
Dialog = Dialog()
|
||||
|
||||
Dialog.show()
|
||||
sys.exit(app.exec_())
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>317</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>PushButton</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(85, 255, 127);</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="pyqml.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,7 @@
|
|||
# QDialog中嵌入QML界面并缩放控件
|
||||
|
||||
使用 QQuickWidget()和QQuickView 嵌入的话.qml文件根节点不能为 Window 和ApplicationWindow,
|
||||
只能为 Rectangle 或Item。
|
||||
见 [QMainWindow中嵌入QML ApplicationWindow界面并缩放控件](../QQmlApplicationEngine之qml嵌入qtwidget_qt5.8以上)
|
||||
|
||||
![截图2](ScreenShot/2.gif)
|
Loading…
Reference in a new issue