Results 1 to 16 of 16

Thread: QStackedLayout / QStackedWidget

  1. #1

    Default QStackedLayout / QStackedWidget

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

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

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

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

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

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

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

  3. #3

    Default Re: QStackedLayout / QStackedWidget

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

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

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

    Quote Originally Posted by morraine View Post
    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?

  5. #5

    Default Re: QStackedLayout / QStackedWidget

    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?
    Last edited by morraine; 9th August 2008 at 23:49.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

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

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

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

  7. #7

    Default Re: QStackedLayout / QStackedWidget

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

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

    Quote Originally Posted by morraine View Post
    but ive read you cant do that with c++
    It's not true. Where did you read that?

  9. #9

    Default Re: QStackedLayout / QStackedWidget

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


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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

    Quote Originally Posted by morraine View Post
    how to create a widget into memory
    Simply create it:
    Qt Code:
    1. SomeWidget *w = new SomeWidget();
    2. // or
    3. SomeWidget w;
    To copy to clipboard, switch view to plain text mode 

  11. #11

    Default Re: QStackedLayout / QStackedWidget

    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!

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

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

  13. #13

    Default Re: QStackedLayout / QStackedWidget

    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.

  14. #14
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

    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

  15. #15
    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: QStackedLayout / QStackedWidget

    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.

  16. #16
    Join Date
    Jun 2013
    Posts
    31
    Thanks
    8
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStackedLayout / QStackedWidget

    Thanks a lot...

Similar Threads

  1. QStackedWidget layout problem
    By Banjo in forum Qt Programming
    Replies: 9
    Last Post: 15th May 2008, 00:15
  2. Replies: 4
    Last Post: 13th August 2007, 15:28
  3. QStackedWidget fill Postscript image And scroll problem
    By patrik08 in forum Qt Programming
    Replies: 11
    Last Post: 22nd April 2007, 09:30
  4. QStackedLayout vs. QStackedWidget
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2007, 23:43
  5. parsing QtableWidget from a QStackedWidget
    By rosmarcha in forum Qt Programming
    Replies: 10
    Last Post: 13th October 2006, 14:36

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.