PDA

View Full Version : Getting the Menubar and Toolbar on the same row in QT



sangs_shenoy
15th February 2012, 11:33
Hi,

I need to have the Toolbar on the same row as the Menubar to capitilize on the Vertical space in my application. I want the menubar to occupy 1/3 of the screen followed by the Toolbar. I tried setting the width of the menu via the SetWidth() fn for the menu, but it still continues to occupy the entire horizontal space. I then made a frame of 1/3rd width and added the menubar in this frame, then added the toolbar at the side, problem with this approach is that the application allows customizable menu's. So when we add a new menu to the menubar I would like the Toolbar to automatically shrink in size, I would appreciate any ideas on how I can achieve this.

Regards,
Sangeeta.

marcvanriet
16th February 2012, 12:16
Hi,

You could put the menubar inside the QToolbar using yourtoolbar->insertWidget( ).

Regards,
Marc

sangs_shenoy
20th February 2012, 07:00
Thanks Marc for your reply. I guess I skipped mentioining that I want the menubar to be fixed and not dockable, whereas the actual toolbar should be dockable. So that would mean making two toolbars one holding the menu and the other for the toolbar? Also when I increase the width of the menu dynamically in the application, how do I trigger the other toolbar to shrink in size?

I dont need the menubar within the Toolbar essentially, is there some way of specifying a width for the QMenubar and then docking the Toolbar after this width?

Regards,
Sangeeta.

ChrisW67
20th February 2012, 07:36
I dont need the menubar within the Toolbar essentially, is there some way of specifying a width for the QMenubar and then docking the Toolbar after this width?
In a main window there iss vertical space for an (optional) menu bar and underneath that vertical space for a tool bar or bars. So yes, you do want your menu inside a tool bar. You can QToolBar::setFloatable() and setMovable() on the tool bar containing the menu. The QMenuBar is naturally as wide as it needs to be to hold the menu titles. The other tool bar will also take as much space as it needs to display its tools, and will get an extension menu when there is insufficient space.

sangs_shenoy
21st February 2012, 04:55
Thanks ChrisW67, that worked for me!

Sangeeta.