[Qt-interest] Menu bar on QtCreator created GUI

Malyushytsky, Alex alex at wai.com
Thu Jul 15 21:12:09 CEST 2010


>> I don't know why I've been mistaken that after the creation the
QWidget should be not visible...

Widgets are not visible until show is called.
For window type widgets you normally do it by explicitly calling show() or other function which will call show itself (for example QDialog::exec() ).
But for child widgets which are not windows parent will take care of showing them.
Just think about QLable for example, you don't call show on it when it is placed into dialog.
Similar happens in your case, I am somehow missed this too.

Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of OS Prog
Sent: Thursday, July 15, 2010 3:57 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Menu bar on QtCreator created GUI

>> 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

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”




More information about the Qt-interest-old mailing list