How to use a GridLayout in combination with exposing data property
-
I am trying to wrap GridLayout inside an Item and exposing the GridLayout's data property as the default property of the item. But this results in two problems.
-
I get a crash when exiting the application.
- This may in fact be a bug in Qt itself and it might also already been fixed, if not I will report it after fixing 2. I am only able to test on Windows 7 using Qt 5.7.0 MSVC2015 32.bit at the moment.
-
How to use the attached Layout property? Take look in the following example, which results in the error: "Non-existent attached object" on line "Layout.alignment: Qt.AlignBottom | Qt.AlignRight".
//MyCustomLayout.qml import QtQuick 2.7 import QtQuick.Layouts 1.3 Item { default property alias data: layout.data //Some other QML components not to be within GridView here. GridLayout { id: layout anchors.fill: parent } //Some other QML components not to be within GridView here. } //main.qml import QtQuick.Controls 2.0 ApplicationWindow { id: root visible: true height: 1024 width: 768 MyCustomLayout { anchors.fill: parent Button { Layout.alignment: Qt.AlignBottom | Qt.AlignRight } } }
-
-
in addition to previous post, if you want to achieve the way your code exist, here is the sample.
MyGrid.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3Item {
property alias lyout: lay
GridLayout {
id: lay
anchors.fill: parent
}
function addObject(val){
val.parent = lay
}
}=========
MyApp.qmlimport QtQuick 2.5
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3ApplicationWindow {
id: root
visible: true
height: 1024
width: 768MyGrid { anchors.fill: parent id : myGrid Button { id : b1 text : "Ali" Layout.alignment: Qt.AlignBottom | Qt.AlignRight parent : myGrid.lyout } Button { id : b2 text : "Pradeep" Layout.alignment: Qt.AlignBottom | Qt.AlignRight parent : myGrid.lyout } Component.onCompleted:{
// myGrid.addObject(b1)
// myGrid.addObject(b2)
// b1.parent = myGrid.lyout
// b2.parent = myGrid.lyout
}
}
} -
You item stucture is now:
ApplicationWindow { Item{ GridLayout {} Button{} }}
not
ApplicationWindow { Item{ GridLayout { Button{} }}}
That causes number 2. The button isn't inside the layout.
-
@Eeli-K Are you sure about that item structure? When aliasing the default property is should be added with the aliased origin as its parent no?