ButtonLayout example syntax error [answered]
With respect to the documentation of a ButtonLayout example for SFOS;
import QtQuick 2.2
import Sailfish.Silica 1.0
Page {
ButtonLayout {
anchors.width: parent.width // <---- this line
Button {
text: "Button1"
}
Button {
text: "Button2"
}
Button {
text: "Button3"
}
}
}
This throws an error in the SDK, as I would expect it to.....anchors.width?, clearly this should be width: parent.width
, then the example works.
Also, the example, along with many others, are somewhat lacking any context. Many use cases for buttons might be on pages in apps or settings, so why not set an example of how you could arrange 3 buttons on a page, like the following;
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
SilicaFlickable {
anchors.fill: parent
Column {
id: column
width: page.width
spacing: Theme.paddingLarge
PageHeader { title: qsTr("Button layout") }
ButtonLayout {
width: parent.width
Button {
text: "Button 1"
onClicked: {
console.log("Button 1 clicked")
}
}
Button {
text: "Button 2"
onClicked: {
console.log("Button 2 clicked")
}
}
Button {
text: "Button 3"
onClicked: {
console.log("Button 3 clicked")
}
}
}
}
}
}
Good catch, thank you! Actually ButtonLayout, as a layout, does not need size bindings. so it will be fixed by simply removing the line. More complex example would not be suitable here, according to Silica devs: "We should do more full-screen view layout examples, but maybe not in API documentation, there short snippets that you can easily copy&paste to your project are the better."
martyone ( 2020-01-16 14:19:14 +0200 )edit