Инструменты пользователя

Инструменты сайта


develop:pyton:pyqt

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
develop:pyton:pyqt [2022/05/08 11:42]
admin
develop:pyton:pyqt [2022/05/08 13:37] (текущий)
admin
Строка 90: Строка 90:
  
 <details> <details>
-<summary>:!: </summary>+<summary>:!: Форма Qml, связь сигнало-слота</summary> 
 +Подключение модулей нужно проверить, есть лишние 
 <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, message):
 +        print('Your message: "'+ message +'"')
 +
 +app= QGuiApplication(sys.argv)
 +view= QQmlApplicationEngine('win.qml')
 +mes = Messenger()
 +
 +ctx = view.rootContext()
 +ctx.setContextProperty("messenger", mes)
 +
 +sys.exit(app.exec_())
 +</code>
 +
 +<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: "darkgray"
 +        anchors.horizontalCenter: page.horizontalCenter
 +        y: 120
 +        MouseArea {
 +            id: buttonMouseArea
 +            objectName: "buttonMouseArea"
 +            anchors.fill: parent
 +            onClicked: {
 +                messenger.PrintMessage("da suka daaaa sukaaa")
 +            }
 +        }
 +        Text {
 +            id: buttonText
 +            text: "Press me!"
 +            anchors.horizontalCenter: button.horizontalCenter
 +            anchors.verticalCenter: button.verticalCenter
 +            font.pointSize: 16
 +        }
 +    }
 +}
 </code> </code>
 </details> </details>
develop/pyton/pyqt.1652010139.txt.gz · Последнее изменение: 2022/05/08 11:42 — admin