In Qt 5.4, the template when creating a new "QtQuick UI File" generates two files: MyScreen.qml
and MyScreen.ui.qml
.
The MyScreen.ui.qml
file seems to be for UI only, since Qt Creator suggests you should only edit it in design mode. That implies that I should be creating UI objects (labels, buttons, etc...) there and somehow referring to them in the MyScreen.qml
file where the logic would go. In principle this sounds great but, unfortunately Qt doesn't come with any examples of how to work with these 2 files.
Here are the contents of those files:
MyScreen.qml
:
import QtQuick 2.4
MyScreen {
}
MyScreen.ui.qml
(I added the Text label in design mode):
import QtQuick 2.4
Item {
width: 400
height: 400
Text {
id: text1
x: 144
y: 151
width: 103
height: 31
text: qsTr("Text")
font.pixelSize: 12
}
}
I tried instantiating a MyScreen
for use in a StackView
(see below), but (unsurprisingly) I don't see the label.
main.qml
:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
Window {
visible: true
StackView {
id: stack
anchors.fill: parent
initialItem: myscreen
}
MyScreen {
id: myscreen
anchors.fill: parent
}
}
Any pointers for a QML newbie?