PDA

View Full Version : Using QStackedWidget for navigation



radioraheem
18th March 2016, 03:43
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!

anda_skoa
18th March 2016, 08:58
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,
_

d_stranz
18th March 2016, 20:25
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.