Qt Creator,在菜单栏中指定位置插入自定义菜单
我用 Qt Creator 创建了一个菜单栏和一些菜单。必须对其中一个菜单进行编码才能使用 QActionGroup
功能。现在可以轻松地将我的自定义菜单添加到菜单栏:
printMenu = menuBar()->addMenu(tr("&Print"));
但我的菜单将位于菜单栏的最后位置。如何在指定位置添加菜单? (例如“文件”菜单之后的第二个位置)
问候语
I have created a menu bar and some menus with Qt creator. One of the menus had to be coded to use QActionGroup
features. Now it is easy to add my custom menu to the menu bar with:
printMenu = menuBar()->addMenu(tr("&Print"));
but my menu will be in the last position of the menu bar. How do I add my menu at a specified place? (e.g. the second place right after the File menu)
Greetings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 QMenuBar::insertMenu 与 QMenu::menuAction。
例如,如果要在“帮助”菜单之前的位置动态插入“打印”菜单,可以执行以下操作:
Use QMenuBar::insertMenu in conjunction with QMenu::menuAction.
For example, if you want to dynamically insert the "Print" menu at the location before the "Help" menu, you can do something like this:
如果您想在菜单栏中间添加一个子菜单,这并不是一件小事。没有直接的 API 可以做到这一点,但您可以通过操纵 QWidget 的内部操作来实现这一点(QMenu::addMenu 只是调用 QWidget::addAction(menu->menuAction()) 。
理论上,您可以操作 QMenuBar::actions(),但我从未这样做过。
当我必须处理这个问题时,我只是从另一个数据集重建了菜单(在您最喜欢的搜索引擎中查找 qmdilib)。 code> 你会看到我的解决方案)。
If you want to add a sub menu in the middle of the menubar, this is not trivial. There is no direct API to do this but you can probably pull that out byt manipulating the internal actions of QWidget (QMenu::addMenu just calls
QWidget::addAction(menu->menuAction())
.In theory, you can manipulate QMenuBar::actions(), but I never did it.
When I had to do handle this problem, I just reconstructed the menu from another dataset (look in your favorite search engine for
qmdilib
and you will see my solution).