-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_quick.py
More file actions
109 lines (85 loc) · 3.04 KB
/
test_quick.py
File metadata and controls
109 lines (85 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import sys
import os
# ================= Setup Start =================
# Add install dir to sys.path
install_dir = os.path.join(os.getcwd(), "out", "install", "x64-msvc-Release")
sys.path.append(install_dir)
# ================= Setup End =================
from PySide6.QtCore import QUrl, Qt
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
from PyQWindowKit import Quick
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
# Register QWindowKit types for QML
# Note: In the C++ example, it's QWK::registerTypes(&engine).
# In Python binding, it should be exposed as Quick.registerTypes(engine)
Quick.registerTypes(engine)
# Load QML
qml_content = b"""
import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QWindowKit 1.0
Window {
id: window
width: 800
height: 600
visible: false // Hide first to prevent flickering
title: "PyQWindowKit Quick Demo"
Component.onCompleted: {
windowAgent.setup(window)
window.visible = true
}
WindowAgent {
id: windowAgent
}
Rectangle {
anchors.fill: parent
color: "#2b2b2b"
Rectangle {
id: titleBar
height: 32
width: parent.width
color: "#3c3c3c"
anchors.top: parent.top
Text {
text: window.title
color: "white"
anchors.centerIn: parent
}
// Use WindowAgent's helper to make this area draggable
TapHandler {
onTapped: if (eventPoint.device.pointerType === PointerDevice.Mouse) window.startSystemMove()
}
// Note: Real dragging usually requires WindowItemDelegate or setting title bar to agent
// In pure QML usage of QWindowKit, we set the title bar like this:
Component.onCompleted: windowAgent.setTitleBar(titleBar)
}
Text {
text: "Hello from QML + PyQWindowKit!"
color: "white"
anchors.centerIn: parent
font.pixelSize: 24
}
Button {
text: "Close"
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: 20
onClicked: Qt.quit()
}
}
}
"""
qml_file = os.path.join(os.getcwd(), "temp_demo.qml")
with open(qml_file, "wb") as f:
f.write(qml_content)
engine.load(QUrl.fromLocalFile(qml_file))
if not engine.rootObjects():
sys.exit(-1)
ret = app.exec()
if os.path.exists(qml_file):
os.remove(qml_file)
sys.exit(ret)