JaySDC
7th September 2015, 09:36
Hi,
I'm Jay and even though I was always around computers, I am completely new to QT with some knowledge and background in coding but rather small to be honest.
Background stuff:
I have an arcade cab running with a PC backbone.
I have a very specific need for a FrontEnd that will allow me to browse/access easily the different categories and different titles (i.e games) in each category.
I used a QT caroussel to achieve that. A friend is helping me out.
Here is my problem:
I have a ListModel that contains 2 ListElements
Each ListElement is populated with all the "*.png" of a folder (two different folders, one contains 5 png files, the other 42 png files)
Pressing Up or Down switches from one ListElement to the other (they're called TARGET and VERSUS)
Pressing LEFT or RIGHT switches, while positioned on a specific ListElement, from one item to the next (TARGET contains 5 items, VERSUS contains 42)
With the code below, when I press LEFT or RIGHT, it affects the position of BOTH ListElements, regardless of that ListElement being visible or not.
Even though only one ListElement is visible/active, the other IS affected and when I switch back to it, the position/currentIndex (i.e the PNG highlighted) CHANGED compared to the last time we browsed THIS ListElement.
I guess it's the basic behavior of QT.
I want my code to do the following:
For each ListElement (TARGET and VERSUS), always remember the position we're at in order to:
Restore/Refresh that specific position when we cycle BACK to this SPECIFIC ListElement
Demo:
we're at position 3 on TARGET.
we switch to VERSUS.
we go crazy with LEFTs and RIGHTs.
we go back to TARGET
TARGET automatically switches back to last known position : 3
Here is what I tried with global variables initially set at 0 (one for each ListElement):
Item {
// verylow res, using native arcade system capabilities
width: 640
height: 240
//We start at position 0 of each ListElement, i.e Category
property int targetSubTypePosition: 0
property int versusSubTypePosition: 0
property int indexSubTypePath: 0
color: "black"
//Populates the 2 ListElements, each with the content of a folder. We only scan for .png
ListModel {
id: subTypeModel
ListElement { name: "YOKO_TG_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/" ; position: 0}
ListElement { name: "YOKO_VS_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_VS_/" ; position: 0}
}
PathView {
id: gameListView
pathItemCount: 14
anchors.fill: parent
focus: true
//Go to next PNG
Keys.onLeftPressed: incrementCurrentIndex()
//Go to previous PNG
Keys.onRightPressed: decrementCurrentIndex()
//Switch to next category. They cycle around. The first "if" makes sure it cycles
Keys.onUpPressed: {
if (indexSubTypePath == subTypeModel.count -1) {
indexSubTypePath = 0;
} else {
indexSubTypePath++;
}
//This is where I "try" to save the last known position of the category that we leave, then I "try" to restore the last known position of the category that we reach
if (indexSubTypePath == 0) {
targetSubTypePosition = currentIndex;
currentIndex = versusSubTypePosition;
} else {
versusSubTypePosition = currentIndex;
currentIndex = targetSubTypePosition;
}
}
//Switch to next category. They cycle around. The first "if" makes sure it cycles
Keys.onDownPressed: {
if (indexSubTypePath == 0) {
indexSubTypePath = subTypeModel.count -1;
} else {
indexSubTypePath--;
}
//This is where I "try" to save the last known position of the category that we leave, then I "try" to restore the last known position of the category that we reach
if (indexSubTypePath == 0) {
targetSubTypePosition = currentIndex;
currentIndex = versusSubTypePosition;
} else {
versusSubTypePosition = currentIndex;
currentIndex = targetSubTypePosition;
}
}
Keys.onSpacePressed: {
positionViewAtIndex(currentIndex, ListView.SnapPosition);
}
model : gameListModel
FolderListModel {
id: gameListModel
nameFilters: ["*.png"]
folder: subTypeModel.get(indexSubTypePath).path//"file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/"
}
This is my full code (the whole project):
https://www.dropbox.com/sh/rv7nz858cfep4wt/AAAdxs4Izp4jVDCb8M8KN8yOa?dl=0
Yours,
--Jay
I'm Jay and even though I was always around computers, I am completely new to QT with some knowledge and background in coding but rather small to be honest.
Background stuff:
I have an arcade cab running with a PC backbone.
I have a very specific need for a FrontEnd that will allow me to browse/access easily the different categories and different titles (i.e games) in each category.
I used a QT caroussel to achieve that. A friend is helping me out.
Here is my problem:
I have a ListModel that contains 2 ListElements
Each ListElement is populated with all the "*.png" of a folder (two different folders, one contains 5 png files, the other 42 png files)
Pressing Up or Down switches from one ListElement to the other (they're called TARGET and VERSUS)
Pressing LEFT or RIGHT switches, while positioned on a specific ListElement, from one item to the next (TARGET contains 5 items, VERSUS contains 42)
With the code below, when I press LEFT or RIGHT, it affects the position of BOTH ListElements, regardless of that ListElement being visible or not.
Even though only one ListElement is visible/active, the other IS affected and when I switch back to it, the position/currentIndex (i.e the PNG highlighted) CHANGED compared to the last time we browsed THIS ListElement.
I guess it's the basic behavior of QT.
I want my code to do the following:
For each ListElement (TARGET and VERSUS), always remember the position we're at in order to:
Restore/Refresh that specific position when we cycle BACK to this SPECIFIC ListElement
Demo:
we're at position 3 on TARGET.
we switch to VERSUS.
we go crazy with LEFTs and RIGHTs.
we go back to TARGET
TARGET automatically switches back to last known position : 3
Here is what I tried with global variables initially set at 0 (one for each ListElement):
Item {
// verylow res, using native arcade system capabilities
width: 640
height: 240
//We start at position 0 of each ListElement, i.e Category
property int targetSubTypePosition: 0
property int versusSubTypePosition: 0
property int indexSubTypePath: 0
color: "black"
//Populates the 2 ListElements, each with the content of a folder. We only scan for .png
ListModel {
id: subTypeModel
ListElement { name: "YOKO_TG_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/" ; position: 0}
ListElement { name: "YOKO_VS_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_VS_/" ; position: 0}
}
PathView {
id: gameListView
pathItemCount: 14
anchors.fill: parent
focus: true
//Go to next PNG
Keys.onLeftPressed: incrementCurrentIndex()
//Go to previous PNG
Keys.onRightPressed: decrementCurrentIndex()
//Switch to next category. They cycle around. The first "if" makes sure it cycles
Keys.onUpPressed: {
if (indexSubTypePath == subTypeModel.count -1) {
indexSubTypePath = 0;
} else {
indexSubTypePath++;
}
//This is where I "try" to save the last known position of the category that we leave, then I "try" to restore the last known position of the category that we reach
if (indexSubTypePath == 0) {
targetSubTypePosition = currentIndex;
currentIndex = versusSubTypePosition;
} else {
versusSubTypePosition = currentIndex;
currentIndex = targetSubTypePosition;
}
}
//Switch to next category. They cycle around. The first "if" makes sure it cycles
Keys.onDownPressed: {
if (indexSubTypePath == 0) {
indexSubTypePath = subTypeModel.count -1;
} else {
indexSubTypePath--;
}
//This is where I "try" to save the last known position of the category that we leave, then I "try" to restore the last known position of the category that we reach
if (indexSubTypePath == 0) {
targetSubTypePosition = currentIndex;
currentIndex = versusSubTypePosition;
} else {
versusSubTypePosition = currentIndex;
currentIndex = targetSubTypePosition;
}
}
Keys.onSpacePressed: {
positionViewAtIndex(currentIndex, ListView.SnapPosition);
}
model : gameListModel
FolderListModel {
id: gameListModel
nameFilters: ["*.png"]
folder: subTypeModel.get(indexSubTypePath).path//"file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/"
}
This is my full code (the whole project):
https://www.dropbox.com/sh/rv7nz858cfep4wt/AAAdxs4Izp4jVDCb8M8KN8yOa?dl=0
Yours,
--Jay