Results 1 to 11 of 11

Thread: Multi-page application and QStackedWidget

  1. #1
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Multi-page application and QStackedWidget

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Multi-page application and QStackedWidget

    These posts are always so much fun to answer :-)

    Quote Originally Posted by Mek82 View Post
    -) 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.

  3. The following user says thank you to tbscope for this useful post:

    Mek82 (31st October 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multi-page application and QStackedWidget

    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

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multi-page application and QStackedWidget

    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.

  6. The following user says thank you to ChrisW67 for this useful post:

    Mek82 (31st October 2010)

  7. #5
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multi-page application and QStackedWidget

    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

  8. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multi-page application and QStackedWidget

    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.

  9. The following user says thank you to ChrisW67 for this useful post:

    Mek82 (31st October 2010)

  10. #7
    Join Date
    Oct 2010
    Posts
    7
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Maemo/MeeGo

    Default Re: Multi-page application and QStackedWidget

    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.

  11. The following user says thank you to jamie721 for this useful post:

    Mek82 (31st October 2010)

  12. #8
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multi-page application and QStackedWidget

    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

  13. #9
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Multi-page application and QStackedWidget

    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?

  14. #10
    Join Date
    Oct 2010
    Posts
    13
    Thanks
    8
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multi-page application and QStackedWidget

    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.

  15. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multi-page application and QStackedWidget

    Quote Originally Posted by Mek82 View Post
    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.

Similar Threads

  1. Replies: 7
    Last Post: 15th November 2012, 15:22
  2. multi page Application
    By ilpaso in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2010, 10:36
  3. A multi-windowed application with Qt
    By ouekah in forum Newbie
    Replies: 4
    Last Post: 13th April 2010, 16:44
  4. QStackedWidget page with different size
    By nina1983 in forum Qt Tools
    Replies: 1
    Last Post: 26th July 2008, 11:58
  5. Multi-Page PDF Output
    By igor in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 05:10

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.