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. When to use StackView
Forum Updated to NodeBB v4.3 + New Features

When to use StackView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 727 Views 1 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.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by
    #1

    Hi,

    This might be a beginner question, but I am not really sure when it is appropriate to use a StackView. Right now, I have it like this:

    Item {
        id: mainWindow
    
        Screen1 {
            id: screen1
        }
        Screen2 {
            id: screen2
        }
        Screen3 {
            id: screen3
        }   
    }
    

    And when I want to navigate between my items, I set their visible properties accordingly. I wonder what the advantage of StackView is. Are the items created dynamically in a StackView? Does it offer other advantages?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      The more screens you add, the harder it is to maintain visibility setting.

      With StackView you get:

      • attached properties
      • transition effects
      • ease of adding / removing screens
      • ability to search through the stack
      • no need to worry about background screens showing up behind current one
      • ability to manage the memory better (pages are may stay uninitialized until they are shown)

      But if manually setting visibility is enough for your case, then it's a perfectly good solution.

      (Z(:^

      1 Reply Last reply
      4
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3

        Thank you for the answer. As my application might get too big to initialize everything at startup, I thought it might make sense to dynamically create them. In a StackView, if I push a new screen, is it then created dynamically?

        ODБOïO sierdzioS 2 Replies Last reply
        0
        • M maxwell31

          Thank you for the answer. As my application might get too big to initialize everything at startup, I thought it might make sense to dynamically create them. In a StackView, if I push a new screen, is it then created dynamically?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          @maxwell31 hi,
          Doc :

          If the only argument needed is "item", the following short-hand notation can be applied:
          
          stackView.push(yourItem)
          
          You can push several items in one go by using an array of property lists. This is more efficient than pushing items one by one, as StackView can then load only the last item in the list. The rest will be loaded as they are about to become the current item (which happens when the stack is popped). The following example shows how to push an array of items:
          
          stackView.push([{item: yourItem1}, {item: yourItem2}])
          
          1 Reply Last reply
          2
          • M maxwell31

            Thank you for the answer. As my application might get too big to initialize everything at startup, I thought it might make sense to dynamically create them. In a StackView, if I push a new screen, is it then created dynamically?

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @maxwell31 said in When to use StackView:

            In a StackView, if I push a new screen, is it then created dynamically?

            Yes, see @LeLev 's answer.

            As the documentation suggests, it's good to wrap such items in Component, then they are parsed at startup (so you get QML errors early), but not loaded until you push them to the stack view.

            If you need to do it even more dynamically, you can push QML file name or use Qt.createComponent(). At least I think it should also work ;-) But then the QML is parsed during push - which is slightly worse when it comes to error reporting.

            (Z(:^

            1 Reply Last reply
            3

            • Login

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