Skip to content

Commit ffdd45f

Browse files
committed
example
1 parent 9e4eaea commit ffdd45f

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
build*

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(foo LANGUAGES CXX)
4+
5+
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
6+
7+
set(CMAKE_AUTORCC ON)
8+
9+
add_executable(foo main.cpp qml.qrc)
10+
11+
12+
target_compile_definitions(foo
13+
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
14+
15+
# conflict with AddQtIosApp.cmake
16+
target_link_libraries(foo PRIVATE Qt5::Core Qt5::Quick)
17+
18+
IF(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
19+
# set(QT_LIBRARIES Qt5::Core Qt5::Quick)
20+
include(QtIosCMake/AddQtIosApp.cmake)
21+
22+
add_qt_ios_app(foo)
23+
ENDIF()

main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <QGuiApplication>
2+
#include <QQmlApplicationEngine>
3+
#include <QQmlContext>
4+
5+
int main(int argc, char *argv[]) {
6+
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
7+
8+
QGuiApplication app(argc, argv);
9+
10+
QQmlApplicationEngine engine;
11+
const QUrl url(QStringLiteral("qrc:/main.qml"));
12+
QObject::connect(
13+
&engine, &QQmlApplicationEngine::objectCreated, &app,
14+
[url](QObject *obj, const QUrl &objUrl) {
15+
if (!obj && url == objUrl)
16+
QCoreApplication::exit(-1);
17+
},
18+
Qt::QueuedConnection);
19+
engine.load(url);
20+
21+
return app.exec();
22+
}

main.qml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import QtQuick 2.7
2+
import QtQuick.Controls 2.1
3+
import QtQuick.Controls 1.4
4+
import QtQml.Models 2.3
5+
import QtQuick.Dialogs 1.2
6+
import QtQuick.Layouts 1.3
7+
import QtQuick.Window 2.1
8+
9+
ApplicationWindow {
10+
11+
id: applicationWindow
12+
visible: true
13+
width: 640
14+
height: 480
15+
function mm_to_px(n) {
16+
if (Screen.pixelDensity > 7) {
17+
return Screen.pixelDensity * 0.8 * n
18+
} else {
19+
return Screen.pixelDensity * n
20+
}
21+
}
22+
Button {
23+
height: mm_to_px(10)
24+
text: "Open Dialog"
25+
id: button
26+
anchors.horizontalCenter: parent.horizontalCenter
27+
anchors.verticalCenter: parent.verticalCenter
28+
onClicked: dialog.open()
29+
}
30+
MouseArea {
31+
id: mouseArea
32+
anchors.fill: applicationWindow
33+
propagateComposedEvents: true
34+
}
35+
36+
Popup {
37+
id: dialog
38+
width: mm_to_px(80)
39+
height: mm_to_px(60)
40+
x: (parent.width - width) / 2
41+
y: (parent.height - height) / 2
42+
modal: true
43+
focus: true
44+
background: Rectangle {
45+
color: "#1e374f"
46+
}
47+
leftMargin: 0
48+
padding: 2
49+
ScrollView {
50+
id: scroll
51+
width: mm_to_px(80)
52+
height: mm_to_px(60)
53+
anchors.fill: parent
54+
clip: true
55+
Column {
56+
57+
Row {
58+
Button {
59+
height: mm_to_px(12)
60+
width: mm_to_px(15)
61+
Text {
62+
anchors.verticalCenter: parent.verticalCenter
63+
anchors.horizontalCenter: parent.horizontalCenter
64+
text: qsTr("Back")
65+
color: "#ffffff"
66+
}
67+
onClicked: dialog.close()
68+
}
69+
70+
Rectangle {
71+
height: mm_to_px(12)
72+
width: scroll.width - mm_to_px(15)
73+
Text {
74+
anchors.verticalCenter: parent.verticalCenter
75+
anchors.horizontalCenter: parent.horizontalCenter
76+
text: "Test"
77+
color: "#ffffff"
78+
}
79+
color: "#1e374f"
80+
}
81+
}
82+
83+
84+
}
85+
}
86+
}
87+
}

qml.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>qtquickcontrols2.conf</file>
5+
</qresource>
6+
</RCC>

qtquickcontrols2.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Controls]
2+
Style=Default

0 commit comments

Comments
 (0)