This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide6.QtCore import QObject, Slot | |
from PySide6.QtGui import QGuiApplication | |
from PySide6.QtQml import QQmlApplicationEngine | |
class Backend(QObject): | |
def __init__(self): | |
super().__init__() | |
self.counter = 0 | |
@Slot() | |
def button_clicked(self): | |
self.counter += 1 | |
print(f"Button clicked {self.counter} times") | |
if __name__ == "__main__": | |
app = QGuiApplication(sys.argv) | |
engine = QQmlApplicationEngine() | |
backend = Backend() | |
engine.rootContext().setContextProperty("backend", backend) | |
engine.load("qml/main.qml") | |
if not engine.rootObjects(): | |
sys.exit(-1) | |
sys.exit(app.exec()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick | |
import QtQuick.Controls | |
ApplicationWindow { | |
visible: true | |
width: 640 | |
height: 480 | |
title: "Hello QML" | |
Button { | |
text: "Click me" | |
anchors.centerIn: parent | |
onClicked: backend.button_clicked() | |
} | |
} |

'날먹을 위한 몸부림 > QT (PySide6)' 카테고리의 다른 글
qml에 material 스타일 적용하기 (2) | 2024.06.21 |
---|---|
python을 백앤드로 사용하는 qml 데모 - 2 (0) | 2024.06.21 |
pyside6에서 윈도우 핫키 컨트롤 사용하기(공용 컨트롤) (2) | 2022.08.30 |
python SetWindowDisplayAffinity (2) | 2022.08.22 |
c++ qt에 material 테마 적용하기 (0) | 2022.05.26 |