[Solved]Something really strange while trying to navigate in Grid
-
something really strange is happening with childat() I've no clue why but it begins really well then it just acts really strange I mean it selects random child griddy is Grid's Id have I found a bug guys?
Keys.onPressed: { if(event.key===Qt.Key_Right){ event.accepted=true griddy.childAt(index+=65,indexi+=0).focus=true } if(event.key===Qt.Key_Down){ event.accepted=true griddy.childAt(index+=0,indexi+=65).focus=true } }
Edited: Please use ``` (3 backticks) for code blocks - p3c0
-
something really strange is happening with childat() I've no clue why but it begins really well then it just acts really strange I mean it selects random child griddy is Grid's Id have I found a bug guys?
Keys.onPressed: { if(event.key===Qt.Key_Right){ event.accepted=true griddy.childAt(index+=65,indexi+=0).focus=true } if(event.key===Qt.Key_Down){ event.accepted=true griddy.childAt(index+=0,indexi+=65).focus=true } }
Edited: Please use ``` (3 backticks) for code blocks - p3c0
-
-
@p3c0 index:x
index:y and I know for sure that every element is width:60... and height: 60 and spacing is 5
and I tested it even in designer and coordinates are correct. Two days have passed still trying to figure out what's wrong@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 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.
-
I think you don't understand what's my problem I have 10 columns and 5 rows and they don't act the way they should not with spacing not even without. At first 20 navigation acts they they do well but after that they act more then strangely
-
-
-
I realized now :/ I did +=that ruined it I should've done just +65 everything works properly now ty P3Co