如何获得禁用 QAction 元素的触发信号? [英] How can I get trigger signal for disabled QAction element?

查看:68
本文介绍了如何获得禁用 QAction 元素的触发信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已禁用 QAction 菜单元素:

I have disabled QAction menu element:

QAction *item = new QAction(itemTitle);
item->setEnabled(false);

我在按下元素后使用 SLOT 连接来调用函数,但它仅适用于已启用的元素:

I use SLOT connection to call function after element was pressed, but it's works only for enabled elements:

QObject::connect(item, SIGNAL(triggered()), this, SLOT(func()));

我的问题是如何为禁用的 QAction 元素触发某些功能?

Qt 5.9.2,MSVC2017 64 位编译器

Qt 5.9.2, MSVC2017 64bit compiler

推荐答案

setEnabled() 属性保存小部件是否已启用.

setEnabled() property holds whether the widget is enabled.

一般来说,启用的小部件处理键盘和鼠标事件;一种禁用的小部件不会.QAbstractButton 例外.

In general an enabled widget handles keyboard and mouse events; a disabled widget does not. An exception is made with QAbstractButton.

当一个小部件被禁用时,所有鼠标和键盘事件也会被禁用.

When a widget is disable, all mouse and keyboard events are also disable.

更多信息:http://doc.qt.io/qt-4.8/qwidget.html#enabled-prop

这篇关于如何获得禁用 QAction 元素的触发信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆