tags:

views:

21

answers:

2

Hello, Is it possible to get layout from QMenuBar object and add items to it. What I am trying to do is a menu bar containing custom widgets (a clock and login/off widget) on the right. This code crashes.

QPushButton *b1 = new QPushButton("Button",ui->menuBar);
QHBoxLayout *rlayout = new QHBoxLayout(this);
ui->menuBar->layout()->addItem(rlayout);
rlayout->addWidget(b1);
b1->show();

Is there any other way? Best regards, Valentin Heinitz

A: 

You should look into QWidgetAction, that allows you to insert custom widget in a menubar. You would then have to call QMenuBar::addAction(QAction*) to put your QWidgetAction in the menubar.

I know that it is not part of your question, but maybe QDockWidget would do a better job for what you need??

Hope this helps.

Live
No, it will not help, sorry. I am porting an application from qt3 to qt4. GUI should look similar, I need a menu-bar. Thank you anyway for answering.
Valentin Heinitz
There could be something in the Qt3 support classes? Have you checked?
Live
Sorry, my first comment refered only to QDockWidget. Adding QWidgetAction to QMenuBar has no effect (s. http://stackoverflow.com/questions/3915327/adding-custom-widgets-to-qmenubar). In Qt4 the Qt3 support class for menu bar lacks the overload of QMenuBar::insertItem with QWidget* parameter :-(
Valentin Heinitz
+1  A: 

Would it be possible to create your own container widget, put the menu bar in on the left, and the other widgets in on the right? That should get you similar functionality and appearance to the Qt3 version of the menu bar.

Caleb Huitt - cjhuitt
Good idea using menu bar on the left. I took a widget and placed two horizontal layouts for menus and buttons. I am managing menus on the left myself but should try your suggestion instead. Thank you!
Valentin Heinitz