Chilly Vanilly Chilly Vanilly - 1 year ago 57
C++ Question

How to make a C++ GUI program in Qt Creator 5.7 that is only 1 window, but every click makes the window have other elements- like a setup wizard

I started making GUI Apps with Qt 5.7 around 2 weeks ago.

Until today I have made a BlackJack game, a basic mini encryption program and 1-2 more programs. Now...I could find any help on how to make an application that actually acts like a Setup Wizard- by that I mean, for example by clicking on next, a lable or any elements are gone and new one appera like a progress bar and belov the contents that are coppied. How is that actually done?
Is it something like

and afterwards the usless elements are hidden like...I dunno
and others show up, or is it literally made by practically "rebuilding" the window with other elements and functionalities?

I appologize for the probably weird yet curious making question AND for the not really well formated text. But I would EXTREMELY appreciate ANY help or advice.

Thank u!

Answer Source

One way to do that is, as you pondered, to destroy the old contents (child widgets) of the window after each page, then repopulate it for the next.

But that's far from ideal IMO: it's wasteful, and it would require you to repeatedly destroy/rebuild things, with all the jumping around that entails, to support Back/Next/Jump to Page # buttons and all routes between different pages. That's more programming and more use of resources to keep unnecessarily tearing down and rebuilding stuff.

Better: give the window a single child of class QStackedWidget. This is a container that can have multiple child widgets but will show only of them at a time. Populate this with a child container for each page of the wizard. Populate each child with the required widgets for that page. Connect buttons, etc in each page to signals to perform required actions - especially the Back/Next/Jump buttons, which you'll set to the active child of the QStackedWidget. Rinse and repeat!

That is: you build the entire stack of pages, ready to go, before ever showing the window. Then, when ready, you just show it, and everything is present and ready to go. Your signals, all properly connected, will take care of everything else: changing between pages, validating input, revealing labels or opening dialogs warning about missing information, etc.