PDA

View Full Version : Qt creator sub-menu



GG2013
27th May 2013, 07:00
9071

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.

Lykurg
27th May 2013, 10:51
There is no build in solution for that. You have to code it yourself :(

Santosh Reddy
27th May 2013, 11:03
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.

GG2013
28th May 2013, 04:24
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.


#include "mainwindow.h"
#include <QApplication>

#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow w;

QWidget *window = new QWidget();
//QWidget *window = new QWidget(&w);

QPushButton *button1 = new QPushButton("Total Traffic");
QPushButton *button2 = new QPushButton("Network Layer");
QPushButton *button3 = new QPushButton("Transport Layer");
QPushButton *button4 = new QPushButton("Application Layer");
QPushButton *button5 = new QPushButton ("Host");

QVBoxLayout *layout = new QVBoxLayout();

layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);

window->setLayout(layout);
window->show();

w.show();

return app.exec();
}

Ginsengelf
28th May 2013, 07:09
Hi, set your window-widget as central widget for w.

Ginsengelf

GG2013
30th May 2013, 03:41
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.