PDA

View Full Version : QStackedLayout / QStackedWidget



morraine
9th August 2008, 18:19
Hello after doing a lot of reading of the qt documentation I've come to the point were i need further clarification on a qt module.

Is the QStackedWidget class the only way that you can have an application with different pages?

when they say that only one stack is visible at a time does that mean that all stacks are loaded into memory and it will just show hide them and anything that is changed or moved within that stack will be there like it is when you come back to it or will it load the code and generate that stack when its requested to be shown and then delete the previous stack and settings for that stack from memory?

does using QStacked Widget impact on performance of the application?

Can you have multiple Qstacked Widgets as children within a parent QStacked Widget and more children with in them as well? (SAY 3 levels Deep)

I'm going to build a huge ERP type application which has many different forms and pages for the application and I'm just would like to know if the QStackedLayout - QStackedWidget programing paradigm is the way to go to achieve this produce this application with the best method available in QT.

jacek
9th August 2008, 20:47
Is the QStackedWidget class the only way that you can have an application with different pages?
No, there's also QTabWidget and QMdiArea, which provide somewhat similar functionality.


when they say that only one stack is visible at a time does that mean that all stacks are loaded into memory
Yes, you have to create all pages before you can add them to the QStackedWidget.


will it load the code and generate that stack when its requested to be shown and then delete the previous stack and settings for that stack from memory?
No, it will just show different page and hide the current one, but you can implement such mechanism easily on your own. You would need some kind of a factory and a manager which will decide what pages to produce and add to the stack and which ones should be deleted.


does using QStacked Widget impact on performance of the application?
Yes, just like with every widget. The more pages you add to the stack, the more memory you will use.


Can you have multiple Qstacked Widgets as children within a parent QStacked Widget and more children with in them as well? (SAY 3 levels Deep)
The docs don't prohibit adding stacked widgets to stacked widget, so most likely you can have as many levels deep as your system can sustain.


I'm going to build a huge ERP type application which has many different forms and pages for the application and I'm just would like to know if the QStackedLayout - QStackedWidget programing paradigm is the way to go to achieve this produce this application with the best method available in QT.
For a very big system using sole QStackedWidget isn't a good solution, because you will use a lot of memory and your application will start slowly, because you will have to create whole GUI when it starts.

Although you can add pages on the fly, using some additional code just as I wrote earlier. Also take a look at QTabWidget, QTabBar, QMdiArea and QDockWidget.

morraine
9th August 2008, 21:46
Hello Jacek, Thanks for your reply.

It sounds like a QStackedLayout / QStackedWidget Class with optional page load and delete, memory management needs developing and adding to the qt class libary.

Do you know how i would go about creating a manager which could add and delete pages on the fly from a stacked widget. Or even add and delete a stacked widget on the fly seeing as i can put unlimited children into a parent stacked widget?

this would be a great function as opening up all the GUI pages for a complex ERP application would just have the computer running like trying to run vista ultimate on a Pentium 2 especially if the end users will be using the cheapest and greenest commodity computer gear

jacek
9th August 2008, 23:15
It sounds like a QStackedLayout / QStackedWidget Class with optional page load and delete, memory management needs developing and adding to the qt class libary.
But Qt isn't going to know when to delete your page nor when and how to create new ones.


Do you know how i would go about creating a manager which could add and delete pages on the fly from a stacked widget.
First of all you have to know how your application is going to know when to create a new page, which page it should be and when to delete it. You should end up with an interface for the manager class. This is an architectural decision. You have to think it through and maybe even construct a simple prototype to know exactly how your GUI is going to work. It reminds me of SAP's screens and their codes.

Qt part of the implementation should be pretty easy, since Qt provides you with proper methods for inserting and removing pages, but the factory might be a bit tricky.


Or even add and delete a stacked widget on the fly seeing as i can put unlimited children into a parent stacked widget?
The question is: do you really need nested stacked widgets? Maybe you need the "managed" version only for top-level pages?

morraine
9th August 2008, 23:37
The question is: do you really need nested stacked widgets? Maybe you need the "managed" version only for top-level pages?


the reason i said if it was possible to add and remove QStacked Widgets is because architectural i could group pages together so that say guys in the sales department will have 5 pages they use all the time and the accounts department may have 6 different pages they use all the time.

OK when i said that there should be a Stacked widget class for adding and deleting pages on the fly i was referring to the methods that are in it all ready (or lack there of). because the remove Widget() method does not actually delete the widget from memory.

Unless you know of a method to Delete the Widget from memory not in this class?

programmatically in know that i have to tell qt to add and delete when its needed some time i probably would not delete the widget and leave it in memory. it just depends on the situation.

But im new to QT and i was not sure of a way to add and delete pages from Qstacked Widgets programmatically in the way i design the application.

Excuse my ignorance but what do you mean by a factory?

jacek
10th August 2008, 01:01
i could group pages together so that say guys in the sales department will have 5 pages they use all the time and the accounts department may have 6 different pages they use all the time.
OK. You can hardcode that or you can devise some mechanism that will allow users to choose what they need, but this really depends on how you plan to expand your application.


because the remove Widget() method does not actually delete the widget from memory.
Yes, removeWidget() just removes the widget from the layout. To delete it you have to use the delete operator.


Excuse my ignorance but what do you mean by a factory?
It's an object which knows how to create other objects. If you had a page factory, then if you would need to show some page, the manager class could check if such page exists and show it or ask the factory to create it.

morraine
10th August 2008, 10:53
Jacek thanks for your help on this mate. ive looked again at the QStackedWidget Class and thought about creating a management class to add widgets on the fly to one QStackedWidget stack, (i think your right as i will only need one stack if im adding and removing the pages on the fly) then remove them with the removeWidget () method and then delete them from memory with the QWidget destroy() method.

removing and destroying sounds quite easy but if i have a stack with one widget at load time when i start to addWidgets() on the fly will qt load that widget/object into memory with that method or do i need to first load that page/widget/object into memory some how with another method, then i can addWidget or insertwidget it to the Stack?

Im doing this in python as well with PYQT so im not sure if this would be a problem as i know with python you can create objects on the fly, but ive read you cant do that with c++ but as pyqt is essentially using c++ classes im not sure if it will fall foul of the same problem.

jacek
10th August 2008, 22:04
if i have a stack with one widget at load time when i start to addWidgets() on the fly will qt load that widget/object into memory with that method or do i need to first load that page/widget/object into memory some how with another method, then i can addWidget or insertwidget it to the Stack?
You can't add a widget to the stack without creating it first.


but ive read you cant do that with c++
It's not true. Where did you read that?

morraine
11th August 2008, 03:12
You can't add a widget to the stack without creating it first.

Ok so i cant add a widget to the stack without creating it first, so do you have any code examples in C++ or python (I'm not fused what language really as i can adapt it if incompatible) of how to create a widget into memory please.



It's not true. Where did you read that?
it was some other forum so that post was obviously wrong don't worry about it.

jacek
11th August 2008, 21:42
how to create a widget into memory
Simply create it:
SomeWidget *w = new SomeWidget();
// or
SomeWidget w;

morraine
11th August 2008, 22:58
So do you mean just create a new object and assign that object to the widget which link the new page into the application and then addwidget or insertWidget() it to the stack?

(basically that simple)

or do you mean that is a class or function called someWidget() and that creates the page with some other code that i must come up with to load the page?

sorry i just need clarification but thanks for all your help!

jacek
12th August 2008, 00:07
So do you mean just create a new object and assign that object to the widget which link the new page into the application and then addwidget or insertWidget() it to the stack?
Yes .

morraine
12th August 2008, 08:11
thanks jacek for your help on this friend i had just been sorting out the theory on this problem as i have been creating pages with the designer and doing other things before i dive into creating my management class to create, track and remove pages on the fly.

Ive got the ammunition to do this now so thanks for the help.

SiddhantR
12th July 2013, 08:18
Can I know if its possible to make a page in QStackedWidget child of another page in the same stacked widget.
Also is it good to have a stacked widget on another stacked widget. I will be having 8 basic stackedwidgets on which I plan to add 8 more stacked widgets. Is it a good idea or should I try for QTabWidget or QMdiArea?
Thank You

ChrisW67
12th July 2013, 08:44
Why did you resurrect a five-year old thread to ask this?


Can I know if its possible to make a page in QStackedWidget child of another page in the same stacked widget.
No, it makes no sense. A page in a QStackedWidget is a child of the QStackWidget and cannot simultaneously be the child of something else.

Also is it good to have a stacked widget on another stacked widget.
Possible, yes. Good, that really depends on exactly what you are expecting the user interaction with this GUI to be.

I will be having 8 basic stackedwidgets on which I plan to add 8 more stacked widgets. Is it a good idea or should I try for QTabWidget or QMdiArea?Not sure exactly what you mean here but stacked pages on stacked pages sounds horrible from this user's point of view.

SiddhantR
12th July 2013, 09:16
Thanks a lot... :)