简体   繁体   English

Qt6 QWidgetAction 替换“setMenu”?

[英]Qt6 QWidgetAction replacement for 'setMenu'?

in Qt5 I used a QWidgetAction to create a custom looking menu entry, then I added a submenu to it using the setMenu method.Qt5中,我使用QWidgetAction创建自定义外观菜单项,然后使用setMenu方法向其中添加子菜单。 But in Qt6 the setMenu method has been removed, how can this be achieved in Qt6 ?但是在Qt6setMenu方法已被删除,如何在Qt6中实现呢? How can a menu item be created with custom widgets in it and a submenu?如何创建包含自定义小部件子菜单的菜单项?

Thanks谢谢

This was made obsolete in this upstream Qt Change.在上游 Qt 变更中已过时。

It personally concerns me that this was made obsolete leaving the API documentation reader clueless at first.我个人担心的是,这已经过时了,一开始 API 文档阅读器一无所知。

Digging a bit deeper, it seems that the reason for obsoleting this method is that QAction was moved from QtWidgets to QtGui .再深入一点,似乎废弃此方法的原因是QAction已从QtWidgets移至QtGui This is to have generic actions both in the QtWidgets and QtQuick worlds.这是为了在QtWidgetsQtQuick世界中都有通用的操作。 It would be suboptimal to duplicate this in both worlds.在两个世界中复制它是次优的。 So far so good.到目前为止,一切都很好。 It makes sense.这说得通。

It is also worth mentioning that the API is not yet removed.还值得一提的是,该 API 尚未删除。 It is just deprecated.它只是被弃用了。 I think it would ever be removed if no one, like yourself, brings this up, or there is a proper replacement for it.我认为,如果没有人像您这样提出这个问题,或者有合适的替代品,它就会被删除。 So, be assured that it would not just be gone anytime soon.因此,请放心,它不会很快消失。

Now, for the future, a QWidgetAction is represented in the containers you add it to by whatever widget you return from createWidget.现在,对于未来, QWidgetAction将在您将它添加到的容器中表示为您从 createWidget 返回的任何小部件。

It seems that you could still use these APIs:看来您仍然可以使用这些 API:

void QWidget::addAction(QAction *action)

and

QAction *QMenu::menuAction() const

With QWidgetAction .使用QWidgetAction

If this still does not cover your use case, I would suggest to open a Jira ticket against the Qt bug tracker to propose a QMenu::setMenuInAction method to replace the obsolete.如果这仍然没有涵盖您的用例,我建议针对 Qt 错误跟踪器打开Jira 票证,以提出QMenu::setMenuInAction方法来替换过时的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM