[Qt-interest] Menu bar on QtCreator created GUI

OS Prog osprog at gmail.com
Thu Jul 15 12:57:02 CEST 2010


>> 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.
>
That's it.
If I call widget->hide(); it works.
I don't know why I've been mistaken that after the creation the
QWidget should be not visible...
Thanks for helping demystifying this.
Regards,
Nik




More information about the Qt-interest-old mailing list