[Qt-interest] Menu bar on QtCreator created GUI

Andreas Pakulat apaku at gmx.de
Thu Jul 15 11:10:37 CEST 2010


On 15.07.10 08:47:10, OS Prog wrote:
> > What is the purpose of this widget you created after initializing ui?
> >
> I have several classes derived from QWidget and I give them a parent
> QMainWindow. Some of them are graphics, others are plots, I have
> nonGUI classes as well.
> > If it is going to be a window, you may add  Qt::Window flag which should fix the problem.
> > QWidget* p = new QWidget(this, Qt::Window);
> >
> > If it is going to be a dialog just it from the QDialog.
> > If you want to display this widget somewhere at the Central Widget area use centralWidget as a parent.
> >
> > As is, I guess QMainWindow is not expecting to have children which are not created with Qt::Window flag.
> >
> Well, it doesn't block all iteractions, but only the QMenuBar. The
> rest of the QMainWindow seems to behave well.

Try to add more top level menu entries to your menubar and you'll notice
it only blocks those that are below the widget itself. This is normal
behaviour, because you're not putting the widget you created into any
layout and also you're not using it with setCentralWidget. Hence this
widget is simply placed at the top-left corner of its parent when the
parent is shown. You don't even need a qmainwindow for this, try this
example:

#include <QtGui>

int main(int c, char** v)
{
    QApplication a(c,v);

    QWidget top;

    QLabel l1("This is a label with along text for demonstration purpose", &top);
    QLabel l2("This is a short label", &top);

    top.show();
    return a.exec();
}

The solution to your problem is to put the widget you're creating either as
centralwidget of the mainwindow or into a layout inside the central widget.

Andreas

-- 
Do something unusual today.  Pay a bill.



More information about the Qt-interest-old mailing list