[Qt-interest] Why I can't see the Menu on my Widget?

Alessandro Portale Alessandro.Portale at trolltech.com
Tue Jun 9 06:57:31 CEST 2009


Hi,

in order to get an application menu, You need to subclass your TopLevel 
Ui from QMainWindow. In the constructur, you can call menuBar() in order 
to obtain a QMenuBar pointer, and to that you can add the actions.

   http://doc.qtsoftware.com/latest/qmainwindow.html#menuBar

Hope that helps,
Alessandro

Kermit Mei schrieb:
> Hello, I create a Menu in the constructor of my MainWidget class, The
> code is like this:
> 
> MainWidget::MainWidget(QWidget *parent)
>   : QWidget(parent)
> {
>   setWindowFlags(Qt::CustomizeWindowHint);
>   setGeometry(0,0,320,224);
>   setMinimumSize(320,224);
>   setMaximumSize(320,224);
> 
>   loadActions("mainmenu");
>   confBar = new QMenuBar();
>   confMenu =
> confBar->addMenu(QPixmap(":/newPrefix/images/config.png"),"test");
> 
> confBar->setGeometry(0,192,32,32);                                                            
> 
>   foreach(QAction *act,confActions)
>     confMenu->addAction(act);
> }
> 
> But when I run it, I can't see the Menu, there's just one empty widget. 
> Why?
> 
> Thanks




More information about the Qt-interest-old mailing list