如何使用 qt 设计器将 QActions 连接到 SLOTS
我使用 qt Designer 创建了一个漂亮的工具栏,并用一些操作填充了它。
我尝试通过单击编辑>来从 qt 设计器以可视方式将操作连接到插槽信号和槽。这不起作用,因为我找不到任何 QAction 信号。
问题
有没有办法将 QAction SIGNAL(triggered()) 连接到 QT 设计器中的插槽? 请帮忙。
PS: 我目前被迫通过代码连接:
QObject::connect(myAction, SIGNAL(triggered()),this, SLOT(myActionWasTriggered()))
但我很懒,我希望使用 qt 设计器进行连接。
I have created a nice looking toolbar using qt Designer and populated it with some actions.
I tried to connect the actions to slots visually from qt designer by clicking edit> signals and slots. This DID NOT WORK because i could not find any QAction signals.
Question.
Is there a way to connect the QAction SIGNAL(triggered()) to my slots within QT designer?
Please help.
PS:
I am currently being forced to connect through code:
QObject::connect(myAction, SIGNAL(triggered()),this, SLOT(myActionWasTriggered()))
but ia am lazy and i wish to connect using qt designer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有“信号/槽编辑器”停靠面板(通过“视图”->“信号/槽编辑器”切换)。
您可以在那里连接您的操作。
您可能还需要通过“更改信号/槽”表单上下文菜单添加自定义槽。
为了节省一些工作,请使用自动连接功能(请参阅 QMetaObject::connectSlotsByName )。基本上,所有以
on_objectName_signalName
特定模式命名的插槽都将自动连接。There's "Signal/Slot Editor" docked panel (Toggled with View->Signal/Slot Editor).
You can connect your actions there.
You may also need to add your custom slots via the "Change signals/slots" form context menu.
To save yourself some work, use the auto-connection feature (see QMetaObject::connectSlotsByName). Basically, all slots named with a specific pattern of
on_objectName_signalName
will be auto-connected.在文档中查看设计器连接模式...如何在设计器中自动连接
Look here in Docs Designer Connection Mode... How to autconnect in the designer
使用“动作编辑器”面板。您可以在“信号和槽编辑器”附近找到它。
Use the "Action editor" panel. You can find it near "Signals & Slots editor".
如果你有菜单,请根据菜单命名你的动作对象,假设你有:
你有5个菜单栏,
那么你将有一组action_x,x是一个数字。请根据你的菜单命名你的x。
更多解释:
假设:
您有 5x2 = 10 ,您有 10 个操作,请进行管理,例如:
以上类型的管理使您的编码变得容易......
If you have menu, Please name your actions object according to menus , Suppose you have:
You have 5 menus bar,
So you'll have a set of action_x , x is a number.Please naming your x according to your menu.
more explaintion:
And suppose :
You have 5x2 = 10 , you have 10 action, please manage such as:
Above type of managing make easy your coding .....