Results 1 to 16 of 16

Thread: QStackedLayout / QStackedWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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

  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
    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?

  3. #3

    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.

  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
    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.

  5. #5

    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.

  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
    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?

  7. #7

    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.

  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
    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 

  9. #9

    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!

  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
    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 .

  11. #11

    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.

  12. #12
    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

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
  •  
Qt is a trademark of The Qt Company.