This my QML ApplicationWindow :
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
GridLayout {
id : grid
anchors.fill: parent
rows : 3
columns : 3
property double colMulti : grid.width / grid.columns
property double rowMulti : grid.height / grid.rows
function prefWidth(item){
return colMulti * item.Layout.columnSpan
}
function prefHeight(item){
return rowMulti * item.Layout.rowSpan
}
// model: 9
Rectangle {
color : 'red'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'yellow'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'green'
Layout.rowSpan : 1
Layout.columnSpan : 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'red'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'yellow'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'green'
Layout.rowSpan : 1
Layout.columnSpan : 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'red'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'yellow'
Layout.rowSpan : 1
Layout.columnSpan: 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
}
Rectangle {
color : 'green'
Layout.rowSpan : 1
Layout.columnSpan : 1
Layout.preferredWidth : grid.prefWidth(this)
Layout.preferredHeight : grid.prefHeight(this)
MouseArea {
anchors.fill: parent
onClicked: {
// how can i change the columnSpan
}
}
}
}
}
How i can change the columnSpan of the last Rectangle onClicked event of the his MouseArea?
In general i want for each Rectangle,when i click on him ,its columnSpan change into 1 or 2 o 3, and the property width of the other two Rectangles in the same row automatically change
before click grid
after click grid