I'm working on a project that needs to call a modal window with a toolbar to do some work on some data before it's loaded. The reason I need the toolbar is the user has a few different possible options that can be combined.
The obvious choice here is a Modal dialog (which I have working right now). The issue is I want a toolbar. This is a two part question:
- Is it possible to add a toolbar to a
QDialog
? (also is it possible to do this in Qt Designer?) - If 1. is not possible, how can I make a
QMainWindow
modal?
If you don't need the built-in drag and drop feature of QMainWindow's toolbars, you can simply add a QToolBar to any layout, including QDialog's layout(). See the DigviJay Patil's answer below for details, which is definitely cleaner conceptually.
Otherwise, please read on.
It is not directly possible to add a
QToolBar
to aQDialog
in the QMainWindow::addToolBar() sense, becauseQDialog
inherits onlyQWidget
and notQMainWindow
, as you noted (hence do not have the methodaddToolBar()
)You can't make a
QMainWindow
modal, but you can insert aQMainWindow
in aQDialog
this way:Code:
Indeed, a
QMainWindow
doesn't necessarily have to be a top-level widget, and you can even insert severalQMainWindow
s as children of a single widget (may not be the wisest choice though, as the user would probably be confused with the separate sets of menu bars, toolbars, dock widgets, etc.).You can simply use the setMenuBar function of the layout manager that is installed on your QDialog:
You can add QToolBar in QDialog. But as a QWidget. Please have a look
As QToolBar is child of QWidget we can add it as Widget. Using Layout you can adjust its position. Please check this link http://developer.nokia.com/community/wiki/How_to_use_QToolBar_and_QToolButton_in_Qt