首页 > 解决方案 > Can a QToolbar be added to a QDockWidget?

问题描述

I have setup my app to have various dock windows within the main window. I am also able to add a toolbar to the main window. However, I would ideally like to add the QToolBar inside one of the QDockWindow instances (or the QWidget that it houses) as the toolbar will be specific to that window.

Is this possible? I'm using a recent version of Qt, 5.10.

标签: qtqt5qmainwindowqdockwidgetqtoolbar

解决方案


我认为这是可能的。

1.QDockWidget可以设置一个QMainWindowbysetWidget()方法。 QMainWindow仅用于主窗口,但不会阻止将其用作子小部件。

2.QToolBar可以通过addToolBar()方法附加到主子窗口。

3.subwidget-mainwindow自然可以有自己的QToolbar

如果您不想QMainWindow用作其 的小部件QDockWidget,您可以将 附加QToolBar为 的子小部件QDockWidget。但是工具栏不能像 QMainWindow 那样移动。

我认为您想将其添加QToolBar并用作QMainWindow. 因此,我建议您将 a 设置QMainWindow为 . 的小部件,然后QDockWidget将您喜欢的任何小部件附加到主窗口。


推荐阅读