PDA

View Full Version : Multi-page application and QStackedWidget



Mek82
28th October 2010, 19:51
Hello,
I would like to have an advice.
I'm developing an a multipage application with Qt 4.6.
I use the designer to create the GUI application.
In the designer I put in the form one QStackedWidget and in each page I put a lot of custom widget, so it's very fast to create a beautifull GUI.
Each page is full of custom widget to obtain a beautifull GUI application, so each page has an a custom widget background (to show an SVG image),a lot of custom PushButton, custom slider and so on...
The GUI application has about 30 pages and probably they will became more.
In my project there is only one class inehrit from QMainWindows that deal all.
I have the following problem:

-) The class inherit from QMainWinow has too many lines of code and it's impossible to read... any solution/advise?
-) The program is too big... too many pages on QStackedWidget and too many custom widgets.. any solution/advise?
-) Now I work on an industrial sbc with Windows XP, but I want to use or windows CE or embedded Linux to reduce the boot time... any advise?

Thank you very much

Best regards

Mek82

tbscope
28th October 2010, 19:57
These posts are always so much fun to answer :-)


-) The class inherit from QMainWinow has too many lines of code and it's impossible to read... any solution/advise?
1. Use the delete or backspace key.
2. Split the file up into several other files, maybe even several other classes.


-) The program is too big... too many pages on QStackedWidget and too many custom widgets.. any solution/advise?
The delete key seems to work here too I guess.
How can anyone answer that question? Split up your program.
You say you want to add even more widgets, and you ask to reduce them.
1. Make up your mind
2. Sketch out a plan on a piece of paper.


-) Now I work on an industrial sbc with Windows XP, but I want to use or windows CE or embedded Linux to reduce the boot time... any advise?
Advice:
1. Ask clear questions. What are you asking for precisely?
2. If you want to use something, use it.

Mek82
28th October 2010, 20:12
Sorry... I'm a beginner... I'm not expert like you, so first of all thank you for the advises.
I've already thought to make more classes for examples one for each page of the QStackedWidget.
Each of this classes inherit QMainWindow and UI::MyForm (the Form where I put the QStackedWidget).
But now I have only improve the legibility of the program... but the program is big yet.
I can't put less custom widget... I have to put them... and using QStackedWidget I use a lot of memory.
So... What I can do?

Thanks

ChrisW67
29th October 2010, 00:04
Start by thinking about making each stacked panel a separate QWidget derivative with a separate class definition and implementation then your main window need only create thirty objects and add them to the QStackedWidget. These thirty object need only be created when they are needed, i.e. when they are requested the first time, and can also be deleted if they become unused. Only the front-most page has be created at start up.

Then think about what is common between your panels and how you might share those elements between panels.

Mek82
29th October 2010, 10:55
Ok... so I could create:
-) One Form "MyForm" where I put the QStackedWidget
-) Thirty or more classes that deal the content of each page
-) One class "MainWindow" inherit from QMainWindow and from Ui::MyForm that deal the interaction between the QStackedWidget pages

At the beginning the class "MainWindow" creates the object of the class Page1, then when the custom PushButton of the class Page1 object is clicked, it will send a signal connected to the slot in the class "MainWindow".
In this slot the Page2 object is created and the Page1 object is deleted.
It's a good idea/solution... but I have to create the GUI of each Pages inside the "Page X" classes and not by Designer.
In this way became longer to create the GUI.
If in the future I have to create a lot of programs with this structure, I will spend a lot of time to create the GUI... with the Designer is very fast.
I know that it is impossible to find a simple, robust and fast way... but if someone has an idea or tell me where I made a mistake please tell me.

Thanks

ChrisW67
31st October 2010, 01:28
At the beginning the class "MainWindow" creates the object of the class Page1, then when the custom PushButton of the class Page1 object is clicked, it will send a signal connected to the slot in the class "MainWindow".
In this slot the Page2 object is created and the Page1 object is deleted.

Unless memory was exceptionally tight you wouldn't generally delete pages that you already created and added to the stacked widget. You just wouldn't create 30 pages up front if 90% of the time only 5 of the pages were used in a typical session. If they use 30 pages then you have to create 30 pages either way.

If this is a wizard-style sequence of pages with Next and Prev buttons then look at QWizard.


It's a good idea/solution... but I have to create the GUI of each Pages inside the "Page X" classes and not by Designer.
In this way became longer to create the GUI.
This is not something forced on you by Qt or Designer. Each of the 30 QWidget-base classes (your PageX classes) can be built with Designer or hand coded - your call.

jamie721
31st October 2010, 14:13
I think the object orientated process would help you alot. go into google and search about object oriantated programming. This will help you understand how you can break stuff up into smaller chunks and also re use code so that you dont have repetative code in your application.

Mek82
31st October 2010, 17:01
I know object-oriented programming, probably I don't know so well, but I followed your advise and I searched in google but I didn't find nothing new.
This multi-page application is not like a wizard-style sequence.
At the moment I have two ideas/solution:

Idea/solution n°1:
-) One Form "MyForm" created using Designer where I put the QStackedWidget and create the GUI (so put in each pages the custom widget using Designer)
-) One class "MainWindow" inherit from QMainWindow and from Ui::MyForm that deal the interaction between the QStackedWidget pages
-) Thirty or more classes that deal the content of each page

In this way I have only improved the legibility

Idea/solution n°2:
-)One Form "MyForm" created using Designer where I put the QStackedWidget
-)One class "MainWindow" inherit from QMainWindow and from Ui::MyForm that deal the interaction between the QStackedWidget pages
-)Thirty Form "PageXXXForm"one for each Page
-)Thirty or more classes inherit from QWidget and Ui::PageXXXForm that deal the content of each page

At the beginning the class "MainWindow" could create all the PageXXX object or only the 5-6 normally used and then create the other when necessary.
But in this way I create a lot of classes one for each page.

Probably solution n°2 is a good solution, but it is possible to do better?

If someone has an idea or tell me where I made a mistake please tell me

Thanks

SixDegrees
31st October 2010, 17:36
Frankly, 30 separate pages - each crammed with customized widgets - sounds hideously complex. I doubt I would bother trying to learn such a complicated interface unless there were some exceptionally good reason to do so.

What, exactly, is this program supposed to do?

Mek82
31st October 2010, 21:56
I think that is the structure to create a lot of different GUI application.
The start screen is full of custom push button (like the Iphone) pushing on them you could go to a specific page where you could go to another page/pages pushing other push button.
So it is easy to have 30 pages.
Obviously only 5-6 pages are often used and the other pages less.
Every page has a lot of custom widget to create a personalized GUI application.
I think that is important to understand the best way to do.

ChrisW67
31st October 2010, 23:06
I know object-oriented programming.
Good, then you will understand that the multiple inheritance approach you have chosen:


-)One Form "MyForm" created using Designer where I put the QStackedWidget
-)One class "MainWindow" inherit from QMainWindow and from Ui::MyForm that deal the interaction between the QStackedWidget pages
-)Thirty Form "PageXXXForm"one for each Page
-)Thirty or more classes inherit from QWidget and Ui::PageXXXForm that deal the content of each page

is only one of several ways to incorporate Designer generated code into your application. You could equally chose the single inheritance approach and save some files. See "Using a Designer UI File in Your Application" in the Designer manual for more information. If you are using Qt Creator then you have options related to the method to use when creating a new UI class.