[Solved]Something really strange while trying to navigate in Grid
-
@Zubalama Maybe due to spacing the items are not found correctly.
I made a similar code for testing. See if this is what you are trying to do:Grid { id: grid focus: true columns: 6 spacing: 5 Rectangle { color: focus ? "red" : "yellow"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "green"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "blue"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "cyan"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "magenta"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "pink"; width: 50; height: 50 } property int index: 0 Keys.onPressed: { if(event.key===Qt.Key_Right){ grid.childAt((index++)*55,0).focus=true } } }
-
@Zubalama Well then,
Grid { id: grid focus: true columns: 3 rows: 3 spacing: 5 Rectangle { color: focus ? "red" : "yellow"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "green"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "blue"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "cyan"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "magenta"; width: 50; height: 50 } Rectangle { color: focus ? "red" : "pink"; width: 50; height: 50 } property int xindex: -1 property int yindex: 0 Keys.onPressed: { if(event.key===Qt.Key_Right) { grid.childAt((++xindex)*55,yindex*55).focus=true } else if(event.key===Qt.Key_Down) { grid.childAt(xindex*55,(++yindex)*55).focus=true } } }
You can just change logic as per your need.
-