Results 1 to 6 of 6

Thread: Qt creator sub-menu

  1. #1
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt creator sub-menu

    Picture1.jpg

    Hi all,
    I am new to Qt. I am using Qt creator to design a GUI as show in the attached picture. It will have a menu bar at the top and each menu will have sub-menu. Now instead of a drop-down menu (which I can do) how can I have them shown on the left side of the window?

    I am using Qt-Creator 2.7.0 based on Qt 4.8.4 (64-bit), and it is installed in a VM Centos 6.4.
    Any help would be greatly appreciated.

  2. The following user says thank you to GG2013 for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt creator sub-menu

    There is no build in solution for that. You have to code it yourself

  4. The following user says thank you to Lykurg for this useful post:


  5. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qt creator sub-menu

    You will need to write a custom menu layout, using one or more of these widgets, QPushButton, QStackedLayout/QStackedWidget. You could use QGridLayout to create the custom container widget, or even use QMainWindow, with menu bars in QDockedWidgets, and display graph as central widget. Either ways fair understanding of Qt Layout system is required.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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


  7. #4
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt creator sub-menu

    Thank you Lykurg and Santosh for your reply.

    I can now have a set of buttons vertically alligned but they open to a separate window (ie. one mainwindow with a menubar that I created
    by typing in IDE, and another one with 5 buttons). Please see the code below. If I try to open in the main window I can't see these 5 buttons. However, with QHBoxLayout they appear in the main window but with very small size and sitting on top of the menubar.

    Also, I suppose I need to somehow connect these buttons with the parent menu for ex. "Live Traffic" button. Because when this particular button is selected/pressed the corresponding buttons should vertically appear on the window (left side).

    Santosh, I also tried QStackedLayout...but it also opens a separate box outside the main. Perhaps I am not doing it right.

    I appreciate your time.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. #include <QWidget>
    5. #include <QVBoxLayout>
    6. #include <QPushButton>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11.  
    12. MainWindow w;
    13.  
    14. QWidget *window = new QWidget();
    15. //QWidget *window = new QWidget(&w);
    16.  
    17. QPushButton *button1 = new QPushButton("Total Traffic");
    18. QPushButton *button2 = new QPushButton("Network Layer");
    19. QPushButton *button3 = new QPushButton("Transport Layer");
    20. QPushButton *button4 = new QPushButton("Application Layer");
    21. QPushButton *button5 = new QPushButton ("Host");
    22.  
    23. QVBoxLayout *layout = new QVBoxLayout();
    24.  
    25. layout->addWidget(button1);
    26. layout->addWidget(button2);
    27. layout->addWidget(button3);
    28. layout->addWidget(button4);
    29. layout->addWidget(button5);
    30.  
    31. window->setLayout(layout);
    32. window->show();
    33.  
    34. w.show();
    35.  
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 30th May 2013 at 11:33. Reason: missing [code] tags

  8. The following user says thank you to GG2013 for this useful post:


  9. #5
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    509
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator sub-menu

    Hi, set your window-widget as central widget for w.

    Ginsengelf

  10. The following user says thank you to Ginsengelf for this useful post:


  11. #6
    Join Date
    May 2013
    Location
    Melbourne
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt creator sub-menu

    Yes, using setCentralWidget() displays it on the same window. I can now also use Signal/Slot to trigger a specific action when a button is pressed.
    Thank you all for your help.

  12. The following user says thank you to GG2013 for this useful post:


Similar Threads

  1. Main menu Qt Creator disappeared
    By inger in forum Newbie
    Replies: 2
    Last Post: 7th May 2012, 09:35
  2. Replies: 1
    Last Post: 21st February 2012, 23:40
  3. Can I delete qt creator menu entry using plugins?
    By mrsomeonee in forum Qt Tools
    Replies: 5
    Last Post: 29th August 2011, 16:53
  4. centos 5.5: can see qt designer, but not qt creator on menu
    By nina pham in forum Installation and Deployment
    Replies: 0
    Last Post: 17th December 2010, 18:49
  5. Replies: 3
    Last Post: 5th March 2009, 07:27

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.