Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. StackView - Remove A View Item Without Disturbing Current View
Forum Updated to NodeBB v4.3 + New Features

StackView - Remove A View Item Without Disturbing Current View

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PSI-lbc
    wrote on last edited by p3c0
    #1

    I'm using a StackView for screen navigation. Currently a couple views are pushed() onto the stack. Now due to a button push the middle views in the stack should be removed so that when the user pushes the "back" button, unwanted stackview states are skipped.

    // remove the "b" view from the stack..back button returns to "a"
    // stack should go from [a,b,c] to [a,c]

    This works per the documentation, BUT..the catch is the program's current view states variables, animations, etc MUST BE PRESERVED..but aren't.

    // sorta works but all current state info, etc is lost for the current "c" view

    stackView.clear()
    stackView.push( [ {item: Qt.resolvedUrl("qrc:/a.qml" ), properties: { objectName: "" }},
                      {item: Qt.resolvedUrl( "qrc:/c.qml" ), properties: { objectName: "c" }}
                    ] );
    

    So I tried this. Saving the current StackView item as a var, then adding it back in after the clear. Doesn't work..blank view.

    //did not work..to get the current "c" item in its current state

    var theCurentItem = stackView.find( function(item) { return item.name === "c"; } )
    stackView.clear()
    stackView.push( [ {item: Qt.resolvedUrl("qrc:/a.qml" ), properties: { objectName: "" }},
                      {item: theCurentItem, properties: { objectName: "c" } }
                    ] );
    

    Any thoughts or help appreciated...

    Edited - Please follow Markdown syntax rules - p3c0

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PSI-lbc
      wrote on last edited by
      #2

      Not really solved but a work-around is to:

      • save the state (ie any variable(s) of interest) in the last item on the stackview
      • clear the stack
      • push back all items except the one being "removed"
      • in the Component.onCompleted of the last item, restore the saved state

      Ulgy...but works if you only have a few variables that need to be preserved on the last item in the stackview.

      I guess another way would be to:

      • have a "skip me" boolean in each item pushed
      • evaluate the boolean after a pop
      • immediately pop again if "true".
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved