Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слева Предыдущая версия | |||
develop:pyton:pyqt [2022/05/08 11:42] admin |
develop:pyton:pyqt [2022/05/08 13:37] (текущий) admin |
||
---|---|---|---|
Строка 90: | Строка 90: | ||
< | < | ||
- | < | + | < |
+ | Подключение модулей нужно проверить, | ||
<code python> | <code python> | ||
+ | import sys, time | ||
+ | from PySide2 import QtWidgets | ||
+ | from PySide2.QtQml import QQmlApplicationEngine | ||
+ | from PySide2.QtCore import QObject, Slot | ||
+ | from PySide2.QtQuick import QQuickView | ||
+ | from PySide2.QtGui import QGuiApplication | ||
+ | |||
+ | class Messenger(QObject): | ||
+ | @Slot(str) | ||
+ | def PrintMessage(self, | ||
+ | print(' | ||
+ | |||
+ | app= QGuiApplication(sys.argv) | ||
+ | view= QQmlApplicationEngine(' | ||
+ | mes = Messenger() | ||
+ | |||
+ | ctx = view.rootContext() | ||
+ | ctx.setContextProperty(" | ||
+ | |||
+ | sys.exit(app.exec_()) | ||
+ | </ | ||
+ | |||
+ | <code qml> | ||
+ | import QtQuick 2.2 | ||
+ | import QtQuick.Window 2.1 | ||
+ | import QtQuick.Controls 1.2 | ||
+ | import QtQuick.Dialogs 1.1 | ||
+ | ApplicationWindow | ||
+ | { | ||
+ | visible: true; width: 360; height: 360 | ||
+ | | ||
+ | Rectangle { | ||
+ | id: button | ||
+ | width: 150; height: 40 | ||
+ | color: " | ||
+ | anchors.horizontalCenter: | ||
+ | y: 120 | ||
+ | MouseArea { | ||
+ | id: buttonMouseArea | ||
+ | objectName: " | ||
+ | anchors.fill: | ||
+ | onClicked: { | ||
+ | messenger.PrintMessage(" | ||
+ | } | ||
+ | } | ||
+ | Text { | ||
+ | id: buttonText | ||
+ | text: "Press me!" | ||
+ | anchors.horizontalCenter: | ||
+ | anchors.verticalCenter: | ||
+ | font.pointSize: | ||
+ | } | ||
+ | } | ||
+ | } | ||
</ | </ | ||
</ | </ |