View Full Version : Is this a bug?

15th September 2008, 20:51
On application startup I create a QMenu then after I create a QWidget alll within the constructor. By createing a QWidget the menu becomes disabled. If the QWidget is created after calling show() everything is fine.
I'm using the commercial version of 4.4.1 installed as is, not rebuilt, and building the project in Visual Studio 2008. I checked my Mac version and it works correctly, but I have done a local rebuild on the Mac.

The code ....


#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QWidget>
#include <QtGui/QAction>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>

class QTApplication : public QMainWindow

QTApplication(QWidget *parent = 0, Qt::WFlags flags = 0);
virtual ~QTApplication();


#include <QtGui/QApplication>
#include "qtapplication.h"

int main(int argc, char *argv[])
QApplication a(argc, argv);
QTApplication w;
return a.exec();

QTApplication::QTApplication(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
if (this->objectName().isEmpty())

this->setWindowTitle(QApplication::translate("QTApplicationClass", "Qt Application", 0, QApplication::UnicodeUTF8));

QMenu* menu = menuBar()->addMenu( tr("File") );
menu->addAction( new QAction(tr("exit"), this) );

// **** Creating this widget is blocking the menu
QWidget* widget = new QWidget(this);


16th September 2008, 11:10
The QWidget is created over top of the menu. I tried it with a QLabel and it does the same thing. Creating the widget before the menu would do the opposite, the menu would be over the widget. Using QMainWindow::setCentralWidget places the widget below the menu. It's not a bug. Creating a widget with out managing its layout will place the widget in the top left corner of its parent.