Skip to content

Commit b35cbc7

Browse files
committed
Ported some of the qtquickcontrols examples
1 parent 888d1e8 commit b35cbc7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3008
-0
lines changed

examples/controls/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
basiclayouts/basiclayouts
2+
gallery/gallery
3+
splitview/splitview
4+
tableview/tableview
5+
touch/touch

examples/controls/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
These examples were ported from [qtquickcontrols](git@gitorious.org:qt/qtquickcontrols.git).
2+
3+
Only the basic ones were ported, in order to demonstrate how easy it is to create a full-fledged UI with Go and QML.
4+
5+
There were a few more, but they that had native modules and those were omitted due to laziness.
6+
7+
In order to run them you might need some extra Qt5 plugins. On Ubuntu those can be installed using this command:
8+
sudo apt-get install qtdeclarative5-controls-plugin qtdeclarative5-xmllistmodel-plugin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"gopkg.in/qml.v1"
6+
"os"
7+
)
8+
9+
func main() {
10+
if err := qml.Run(run); err != nil {
11+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
12+
os.Exit(1)
13+
}
14+
}
15+
16+
func run() error {
17+
engine := qml.NewEngine()
18+
19+
controls, err := engine.LoadFile("main.qml")
20+
if err != nil {
21+
return err
22+
}
23+
24+
window := controls.CreateWindow(nil)
25+
26+
window.Show()
27+
window.Wait()
28+
return nil
29+
}
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21+
** of its contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
42+
43+
44+
45+
import QtQuick 2.2
46+
import QtQuick.Controls 1.1
47+
import QtQuick.Layouts 1.0
48+
49+
ApplicationWindow {
50+
visible: true
51+
title: "Basic layouts"
52+
property int margin: 11
53+
width: mainLayout.implicitWidth + 2 * margin
54+
height: mainLayout.implicitHeight + 2 * margin
55+
minimumWidth: mainLayout.Layout.minimumWidth + 2 * margin
56+
minimumHeight: mainLayout.Layout.minimumHeight + 2 * margin
57+
58+
ColumnLayout {
59+
id: mainLayout
60+
anchors.fill: parent
61+
anchors.margins: margin
62+
GroupBox {
63+
id: rowBox
64+
title: "Row layout"
65+
Layout.fillWidth: true
66+
67+
RowLayout {
68+
id: rowLayout
69+
anchors.fill: parent
70+
TextField {
71+
placeholderText: "This wants to grow horizontally"
72+
Layout.fillWidth: true
73+
}
74+
Button {
75+
text: "Button"
76+
}
77+
}
78+
}
79+
80+
GroupBox {
81+
id: gridBox
82+
title: "Grid layout"
83+
Layout.fillWidth: true
84+
85+
GridLayout {
86+
id: gridLayout
87+
rows: 3
88+
flow: GridLayout.TopToBottom
89+
anchors.fill: parent
90+
91+
Label { text: "Line 1" }
92+
Label { text: "Line 2" }
93+
Label { text: "Line 3" }
94+
95+
TextField { }
96+
TextField { }
97+
TextField { }
98+
99+
TextArea {
100+
text: "This widget spans over three rows in the GridLayout.\n"
101+
+ "All items in the GridLayout are implicitly positioned from top to bottom."
102+
Layout.rowSpan: 3
103+
Layout.fillHeight: true
104+
Layout.fillWidth: true
105+
}
106+
}
107+
}
108+
TextArea {
109+
id: t3
110+
text: "This fills the whole cell"
111+
Layout.minimumHeight: 30
112+
Layout.fillHeight: true
113+
Layout.fillWidth: true
114+
}
115+
}
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21+
** of its contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
import QtQuick 2.2
41+
import QtQuick.Dialogs 1.1
42+
43+
MessageDialog {
44+
icon: StandardIcon.Information
45+
text: "QtQuick.Controls gallery example"
46+
detailedText: "This example demonstrates most of the available Qt Quick Controls."
47+
title: "About Gallery"
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21+
** of its contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
42+
43+
44+
45+
import QtQuick 2.2
46+
import QtQuick.Window 2.1
47+
import QtQuick.Controls 1.1
48+
49+
Window {
50+
id: window1
51+
52+
width: 400
53+
height: 400
54+
55+
title: "child window"
56+
flags: Qt.Dialog
57+
58+
Rectangle {
59+
color: syspal.window
60+
anchors.fill: parent
61+
62+
Label {
63+
id: dimensionsText
64+
anchors.horizontalCenter: parent.horizontalCenter
65+
anchors.top: parent.top
66+
width: parent.width
67+
horizontalAlignment: Text.AlignHCenter
68+
}
69+
70+
Label {
71+
id: availableDimensionsText
72+
anchors.horizontalCenter: parent.horizontalCenter
73+
anchors.top: dimensionsText.bottom
74+
width: parent.width
75+
horizontalAlignment: Text.AlignHCenter
76+
}
77+
78+
Label {
79+
id: closeText
80+
anchors.horizontalCenter: parent.horizontalCenter
81+
anchors.top: availableDimensionsText.bottom
82+
text: "This is a new Window, press the\nbutton below to close it again."
83+
}
84+
Button {
85+
anchors.horizontalCenter: closeText.horizontalCenter
86+
anchors.top: closeText.bottom
87+
id: closeWindowButton
88+
text:"Close"
89+
width: 98
90+
tooltip:"Press me, to close this window again"
91+
onClicked: window1.visible = false
92+
}
93+
Button {
94+
anchors.horizontalCenter: closeText.horizontalCenter
95+
anchors.top: closeWindowButton.bottom
96+
id: maximizeWindowButton
97+
text:"Maximize"
98+
width: 98
99+
tooltip:"Press me, to maximize this window again"
100+
onClicked: window1.visibility = Window.Maximized;
101+
}
102+
Button {
103+
anchors.horizontalCenter: closeText.horizontalCenter
104+
anchors.top: maximizeWindowButton.bottom
105+
id: normalizeWindowButton
106+
text:"Normalize"
107+
width: 98
108+
tooltip:"Press me, to normalize this window again"
109+
onClicked: window1.visibility = Window.Windowed;
110+
}
111+
Button {
112+
anchors.horizontalCenter: closeText.horizontalCenter
113+
anchors.top: normalizeWindowButton.bottom
114+
id: minimizeWindowButton
115+
text:"Minimize"
116+
width: 98
117+
tooltip:"Press me, to minimize this window again"
118+
onClicked: window1.visibility = Window.Minimized;
119+
}
120+
}
121+
}
122+

0 commit comments

Comments
 (0)