Results 1 to 3 of 3

Thread: Using QStackedWidget for navigation

  1. #1
    Join Date
    Mar 2016
    Posts
    2
    Qt products
    Qt5

    Default Using QStackedWidget for navigation

    Very new to this - please excuse me if I'm asking foolish questions. Please feel free to post corrections/suggestions, even if they don't directly answer my question - I'd like to get up to speed quickly!

    I'm putting together a UI of around 50 pages for an embedded device with constrained resources. I am under the impression that for navigating from page to page a QStackedWidget is the way to go.

    Given the size of the UI, should I be creating and adding all the pages to the UI up front, passing the QStackedWidget instance to my page classes and navigating around by using the QStackedWidget::SetCurrentIndex() method (maybe making a big global enum of all my pages)?

    Or is this going to waste a foolish amount of memory?

    Instead should I be clearing out the QStackedWidget every time I'm at the home page and only creating/adding items to it as the user navigates down a particular route (allowing them to navigate back to the home screen)?

    Or am I looking at this completely the wrong way and should be doing something else entirely?!!

    Thanks for any insight!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QStackedWidget for navigation

    You will have to measure the resource impact of both approaches to see if they both fit your contraints.

    Creating all pages up front is obviously easier but will need more memory and increase startup time.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QStackedWidget for navigation

    Presumably you are storing state information (i.e. what is displayed on the page) separately from the page UI itself. If you will only display a single page at a time, then I think you could dispense with the stacked widget entirely and simply display each page dynamically, filling it with the current state upon creation. Hide the page you are navigating off of, create, initialize, and show the new page, then call deleteLater() on the old page. This way you have at most two pages in memory at any time.

Similar Threads

  1. Qt Window navigation
    By jbarrena in forum Newbie
    Replies: 3
    Last Post: 30th March 2014, 11:56
  2. QML screen navigation how to
    By anish in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 27th October 2013, 21:08
  3. QML webview navigation
    By snake91 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd December 2011, 13:22
  4. page navigation
    By ningoji in forum Newbie
    Replies: 2
    Last Post: 5th April 2011, 11:15
  5. Navigation purpose
    By jerkymotion in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2011, 17:59

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.