[Solved] Check which child has the focus in the Column element
-
Send signal from children when they get focus. Or use GridView, it has focus handling built-in.
-
Thank you very much for your answer!
I've got a special focus handling. E.g. when enter is pressed, the focus should be on the textfield of the rectangle and when enter is pressed again, it should move to the next item in the column.
Grid view would need a model. I'm adding the items to the column in C++, so I think it is easier to handle everything in the column, but maybe I'm wrong and just thinking too complicated.
-
It's your choice, obviously. Column is easier, GridView has more features. There is a way to use GridView without a real model. I'll give you an example (copy-paste from live code, so some variables could be hard to understand. Also, it uses JS, not C++):
@
function populateUnits(tmpUnitsList) {
unitsList = tmpUnitsList;for (var i = 0; i < unitsList.length; i++) { var currentUnit = unitsList[i]; unitModel.append({"unitType": currentUnit.unitType, "unitLogo": currentUnit.unitLogo, "unitStatus": currentUnit.unitStatus, "unitSelected": currentUnit.selected}); currentUnit.unitStatusChanged.connect(changeStatus); currentUnit.selectionChanged.connect(selectionChanged); } } ListModel { id: unitModel } Component { id: unitDelegate RosterMenuEntry { backgroundColor: root.backgroundColor entryText: unitType entryLogo: unitLogo entryStatusText: unitStatus selected: unitSelected } } GridView { id: units anchors.topMargin: 2 anchors.leftMargin: 2 interactive: false anchors.top: parent.top anchors.left: parent.left height: (cellHeight * 4) + 3 width: (cellWidth) + 3 flow: GridView.TopToBottom // This means it will act as a Column model: unitModel delegate: unitDelegate }
@
-
So, I start with an empty model, and then add elements with my populateUnits() function. ListModel::append is used here. It's well documented in Qt docs.
-
Thank you, I've done that for other objects which I wanted to display in a list.
But I don't know if I can fill a GridView with different self-made components like a textfield, checkbox,... in the column, this is working fine.I have seen the VisualItemModel, but I think it is not possible to fill this in C++.
-
Could probably be done with Loader as a model - but that seems to be an overkill.