Woody1987
December 14th, 2009, 03:55 AM
Im trying to add a menubar to my Qt application. This application will also use opengl to render stuff in the app. Right now, the only way i can add a menubar is to add it to a layout box. This causes a problem as the menubar is not at the top of the screen. Picture below shows the problem.
http://img190.imageshack.us/img190/9686/screenshot1ee.png
If i do some tinkering i can get the menubar where i want it, but it removes the opengl part.
http://img692.imageshack.us/img692/238/screenshot2v.png
Code:
window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
#include <QtGui>
#include <QMainWindow>
class GLWidget;
class Window : public QWidget
{
Q_OBJECT
public:
Window();
private:
GLWidget *glWidget;
QMenuBar *menubar;
QMenu *menuFile;
QMenu *menuPreferences;
QMenu *menuSimulation;
QMenu *menuHelp;
QToolBar *toolBar;
QAction *actionRun;
QAction *actionPause;
QAction *actionStop;
QAction *actionSetup;
};
#endif
window.cpp
#include <QtGui>
#include "glwidget.h"
#include "window.h"
#include <QMainWindow>
Window::Window()
{
glWidget = new GLWidget;
menubar = new QMenuBar();
menuFile = new QMenu("&File");
menuPreferences = new QMenu("&Preferences");
menuSimulation = new QMenu("&Simulation");
menuHelp = new QMenu("&Help");
menubar->addMenu(menuFile);
menubar->addMenu(menuPreferences);
menubar->addMenu(menuSimulation);
menubar->addMenu(menuHelp);
QVBoxLayout *mainLayout = new QVBoxLayout;
//setMenuBar(menubar);
mainLayout->addWidget(menubar);
mainLayout->addWidget(glWidget);
setLayout(mainLayout);
setWindowTitle(tr("Particle Simulator"));
}
The problem seems to be with window.h, specifically with:
class Window : public QWidget
Changing QWidget to QMainWindow fixes the menubar issue but removes the opengl. How do i get both?
http://img190.imageshack.us/img190/9686/screenshot1ee.png
If i do some tinkering i can get the menubar where i want it, but it removes the opengl part.
http://img692.imageshack.us/img692/238/screenshot2v.png
Code:
window.h
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
#include <QtGui>
#include <QMainWindow>
class GLWidget;
class Window : public QWidget
{
Q_OBJECT
public:
Window();
private:
GLWidget *glWidget;
QMenuBar *menubar;
QMenu *menuFile;
QMenu *menuPreferences;
QMenu *menuSimulation;
QMenu *menuHelp;
QToolBar *toolBar;
QAction *actionRun;
QAction *actionPause;
QAction *actionStop;
QAction *actionSetup;
};
#endif
window.cpp
#include <QtGui>
#include "glwidget.h"
#include "window.h"
#include <QMainWindow>
Window::Window()
{
glWidget = new GLWidget;
menubar = new QMenuBar();
menuFile = new QMenu("&File");
menuPreferences = new QMenu("&Preferences");
menuSimulation = new QMenu("&Simulation");
menuHelp = new QMenu("&Help");
menubar->addMenu(menuFile);
menubar->addMenu(menuPreferences);
menubar->addMenu(menuSimulation);
menubar->addMenu(menuHelp);
QVBoxLayout *mainLayout = new QVBoxLayout;
//setMenuBar(menubar);
mainLayout->addWidget(menubar);
mainLayout->addWidget(glWidget);
setLayout(mainLayout);
setWindowTitle(tr("Particle Simulator"));
}
The problem seems to be with window.h, specifically with:
class Window : public QWidget
Changing QWidget to QMainWindow fixes the menubar issue but removes the opengl. How do i get both?