Results 1 to 10 of 10

Thread: How to remember and reestablish the last currentIndex position of each ListElement?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2015
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default How to remember and reestablish the last currentIndex position of each ListElement?

    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):

    Qt Code:
    1. Item {
    2.  
    3. // verylow res, using native arcade system capabilities
    4. width: 640
    5. height: 240
    6.  
    7.  
    8. //We start at position 0 of each ListElement, i.e Category
    9. property int targetSubTypePosition: 0
    10. property int versusSubTypePosition: 0
    11.  
    12. property int indexSubTypePath: 0
    13.  
    14. color: "black"
    15.  
    16. //Populates the 2 ListElements, each with the content of a folder. We only scan for .png
    17. ListModel {
    18. id: subTypeModel
    19. ListElement { name: "YOKO_TG_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/" ; position: 0}
    20. ListElement { name: "YOKO_VS_"; path: "file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_VS_/" ; position: 0}
    21. }
    22.  
    23. PathView {
    24. id: gameListView
    25. pathItemCount: 14
    26. anchors.fill: parent
    27. focus: true
    28.  
    29. //Go to next PNG
    30. Keys.onLeftPressed: incrementCurrentIndex()
    31.  
    32. //Go to previous PNG
    33. Keys.onRightPressed: decrementCurrentIndex()
    34.  
    35. //Switch to next category. They cycle around. The first "if" makes sure it cycles
    36. Keys.onUpPressed: {
    37. if (indexSubTypePath == subTypeModel.count -1) {
    38. indexSubTypePath = 0;
    39. } else {
    40. indexSubTypePath++;
    41. }
    42.  
    43. //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
    44. if (indexSubTypePath == 0) {
    45. targetSubTypePosition = currentIndex;
    46. currentIndex = versusSubTypePosition;
    47. } else {
    48. versusSubTypePosition = currentIndex;
    49. currentIndex = targetSubTypePosition;
    50. }
    51.  
    52. }
    53.  
    54. //Switch to next category. They cycle around. The first "if" makes sure it cycles
    55. Keys.onDownPressed: {
    56. if (indexSubTypePath == 0) {
    57. indexSubTypePath = subTypeModel.count -1;
    58.  
    59. } else {
    60. indexSubTypePath--;
    61. }
    62.  
    63. //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
    64. if (indexSubTypePath == 0) {
    65. targetSubTypePosition = currentIndex;
    66. currentIndex = versusSubTypePosition;
    67. } else {
    68. versusSubTypePosition = currentIndex;
    69. currentIndex = targetSubTypePosition;
    70. }
    71. }
    72.  
    73. Keys.onSpacePressed: {
    74. positionViewAtIndex(currentIndex, ListView.SnapPosition);
    75. }
    76.  
    77. model : gameListModel
    78. FolderListModel {
    79. id: gameListModel
    80. nameFilters: ["*.png"]
    81. folder: subTypeModel.get(indexSubTypePath).path//"file:///D:/ArcadeLauncher 25.04.2015/DEV_ARCADE/YOKO_TG_/"
    82. }
    To copy to clipboard, switch view to plain text mode 


    This is my full code (the whole project):
    https://www.dropbox.com/sh/rv7nz858c...8M8KN8yOa?dl=0

    Yours,
    --Jay
    Last edited by JaySDC; 7th September 2015 at 09:43.

Similar Threads

  1. how does qt remember toolbar locations
    By ravas in forum Newbie
    Replies: 4
    Last Post: 14th July 2015, 20:03
  2. ListElement refer ListModel id
    By keolsen in forum Qt Quick
    Replies: 0
    Last Post: 13th November 2012, 10:23
  3. Replies: 0
    Last Post: 22nd April 2011, 10:20
  4. remember file path
    By eric in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2008, 16:52
  5. currentIndex().internalPointer() problem
    By xgoan in forum Qt Programming
    Replies: 2
    Last Post: 14th December 2006, 09:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.