Skip to content

Commit 1cf07f2

Browse files
committed
examples: add qt6 qml
1 parent e036f22 commit 1cf07f2

File tree

10 files changed

+114
-3
lines changed

10 files changed

+114
-3
lines changed

examples/qt/qml/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("//bazel/rules:qt.bzl", "qt_cc_binary", "qt_resource")
2+
3+
qt_resource(
4+
name = "qrc",
5+
files = [
6+
"main.qml",
7+
],
8+
)
9+
10+
qt_cc_binary(
11+
name = "bin",
12+
srcs = ["main.cpp"],
13+
deps = [
14+
":qrc",
15+
],
16+
)

examples/qt/qml/README

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# How to Run
2+
3+
Run the following command to compile for x86:
4+
5+
```bash
6+
bazel run //examples/qt/qml:bin
7+
```
8+
9+
Run the following command to compile for aarch64:
10+
11+
```bash
12+
bazel build //examples/qt/qml:bin --platforms=//bazel/platforms:aarch64_linux
13+
```

examples/qt/qml/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <QtCore/QString>
2+
#include <QtQml/QQmlApplicationEngine>
3+
#include <QtQml/QQmlContext>
4+
#include <QtWidgets/QApplication>
5+
6+
auto main(int argc, char *argv[]) -> int {
7+
QGuiApplication app(argc, argv);
8+
9+
QQmlApplicationEngine engine;
10+
11+
QString button_text = "Click me!";
12+
engine.rootContext()->setContextProperty("buttonText", button_text);
13+
14+
engine.load(QUrl(QStringLiteral("qrc:/examples/qt/qml/main.qml")));
15+
16+
return QGuiApplication::exec();
17+
}

examples/qt/qml/main.qml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import QtQuick 6.0
2+
import QtQuick.Controls 6.0
3+
4+
ApplicationWindow {
5+
visible: true
6+
width: 640
7+
height: 480
8+
title: "Qt6 QML Example"
9+
10+
// Define properties
11+
property color bgColor: "lightblue"
12+
property int fontSize: 24
13+
14+
Rectangle {
15+
width: parent.width
16+
height: parent.height
17+
color: bgColor
18+
19+
// Text element that changes based on interaction
20+
Text {
21+
id: label
22+
text: "Adjust me!"
23+
anchors.centerIn: parent
24+
font.pixelSize: fontSize
25+
color: "black"
26+
}
27+
28+
// Slider to adjust font size
29+
Slider {
30+
id: fontSizeSlider
31+
from: 10
32+
to: 100
33+
value: fontSize
34+
anchors.top: label.bottom
35+
anchors.horizontalCenter: parent.horizontalCenter
36+
width: parent.width * 0.8
37+
onValueChanged: {
38+
fontSize = fontSizeSlider.value
39+
}
40+
}
41+
42+
// CheckBox to toggle background color
43+
CheckBox {
44+
text: "Change Background Color"
45+
anchors.top: fontSizeSlider.bottom
46+
anchors.horizontalCenter: parent.horizontalCenter
47+
onCheckedChanged: {
48+
bgColor = checked ? "lightgreen" : "lightblue"
49+
}
50+
}
51+
52+
// Button to reset the font size and background color
53+
Button {
54+
text: "Reset"
55+
anchors.top: checkBox.bottom
56+
anchors.horizontalCenter: parent.horizontalCenter
57+
onClicked: {
58+
fontSize = 24
59+
bgColor = "lightblue"
60+
fontSizeSlider.value = 24
61+
checkBox.checked = false
62+
}
63+
}
64+
}
65+
}
File renamed without changes.

examples/qt/README renamed to examples/qt/ui/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Run the following command to compile for x86:
44

55
```bash
6-
bazel run //examples/qt:bin
6+
bazel run //examples/qt/ui:bin
77
```
88

99
Run the following command to compile for aarch64:
1010

1111
```bash
12-
bazel build //examples/qt:bin --platforms=//bazel/platforms:aarch64_linux
12+
bazel build //examples/qt/ui:bin --platforms=//bazel/platforms:aarch64_linux
1313
```
File renamed without changes.
File renamed without changes.

examples/qt/mainwindow.h renamed to examples/qt/ui/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <QtWidgets/QMainWindow>
77
#include <QtWidgets/QPushButton>
88

9-
#include "examples/qt/ui_mainwindow.h"
9+
#include "examples/qt/ui/ui_mainwindow.h"
1010

1111
class MainWindow : public QMainWindow {
1212
Q_OBJECT
File renamed without changes.

0 commit comments

Comments
 (0)