Results 1 to 4 of 4

Thread: Menus with overlays

  1. #1
    Join Date
    Dec 2017
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Menus with overlays

    Hi all,

    I am developing an application in which the content changes according to menu options located on top and bottom of screen(see picture attached).
    I want to keep these menu options common through all the screens, but only want to change the content in the middle of these pages. Can you let me know the best possible way to do this?

    I tried stack widgets but we have many screens with significant code associated with them, which might cause maintenance issues with a large chunk of code in a single file.

    Any other suggestions?

    Thanks.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Menus with overlays

    which might cause maintenance issues with a large chunk of code in a single file.
    Why do you think that you must put all of the code into a single file if you use a stack widget? A stack widget is simply a container for other widgets that is configured so that only one of those widgets is visible at any time.

    The code for each of the widgets managed by the stack widget can (and almost always should) be defined as a separate class, usually derived from QWidget, and implemented into its own set of source, header, and form (.ui) files. If these classes need to communicate with other parts of your app, then they should emit signals when significant things happen, and the code that creates the stack widget and its contents should connect those signals to slots implemented by the other parts of your application that need to know about those changes.

    You will almost never need to derive a custom class from QStackedWidget (or QTabWidget). You may have a custom class that owns the stack widget and constructs its contents, but the stack widget doesn't care or need to know anything about the widgets it manages.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    vegeta1in (28th December 2017)

  4. #3
    Join Date
    Dec 2017
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Menus with overlays

    Got it working. Thanks a lot!
    Also referred to this video:
    https://www.youtube.com/watch?v=27PvtxWlV-o

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Menus with overlays

    That is a terrible video, and I would be very cautious about using any of that poster's videos as a guide. Just two of the things I saw that were serious errors:

    1 - He defined his stack widget page widgets as automatic member variables of the Application class. (i.e. MachineState machineState; instead of MachineState * machineState). No QWidget instance should ever be declared in this way; instead they should be declared as pointer variables, constructed on the heap (using new()) and given an appropriate parent:

    Qt Code:
    1. // .h
    2.  
    3. class MachineState;
    4. class Settings;
    5.  
    6. class Application : public QWidget
    7. {
    8. Q_OBJECT;
    9.  
    10. // ...
    11.  
    12. private:
    13. MachineState * machineState;
    14. Settings * settings;
    15.  
    16. };
    17.  
    18. // .cpp
    19.  
    20. Application::Application( QWidget * parent )
    21. : QWidget( parent )
    22. // ...
    23. {
    24. ui->setupUi( this );
    25. machineState = new MachineState( this );
    26. settings = new Settings( this );
    27.  
    28. //...
    29. }
    To copy to clipboard, switch view to plain text mode 

    with this code, the two sub-widgets are owned by the Application instance and will be appropriately destroyed when Application is destroyed.

    2 - He doesn't use layouts for any of the page widgets, and he puts the control widgets on the forms with absolute positions and sizes. This will result in ugly behavior when the application widget is resized.

    There are probably more things that would make me ill, but just watching that much made me sick enough.

    Maybe you know enough to use better coding practices than the ones in this video, but if you thought that what you saw was just fine to imitate, well, don't do that. Study the Qt tutorials and examples for much better solutions.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. cascading menus
    By Ronn in forum Newbie
    Replies: 1
    Last Post: 29th May 2015, 19:47
  2. Replies: 0
    Last Post: 20th August 2010, 12:50
  3. Context Menus
    By qtoptus in forum Newbie
    Replies: 0
    Last Post: 25th June 2010, 15:18
  4. QFileSystemModel file icon overlays
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2009, 11:06
  5. Context Menus
    By rodlbr in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 16:30

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.