[转帖]QPushButton保持按压的问题_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3566 | 回复: 0   主题: [转帖]QPushButton保持按压的问题        下一篇 
clover
注册用户
等级:少校
经验:843
发帖:73
精华:0
注册:2013-6-28
状态:离线
发送短消息息给clover 加好友    发送短消息息给clover 发消息
发表于: IP:您无权察看 2013-6-28 13:42:03 | [全部帖] [楼主帖] 楼主

程序目前是这么设计的:
按住按钮,一直不断的做一件事
松开按钮时,做一次另一件事

正常情况下,没有问题,在QPushButton的发射的信号pressed和released对应的槽中各自处理事务。现在的问题是,当程序内部因为其他原因弹出一个对话框时,按钮恢复弹起状态,但是似乎不发送released信号,所以就出问题了

请教,如何解决这一问题?需要派生QPushButton并处理eventfilter吗?是的话,具体如何做?谢谢

解决办法:

正常情况release signal会收到,您可以在qapplication 中添加 eventfilter 来看一下事件。
参考代码如下

Installs an event filter filterObj on this object. For example:
monitoredObj->installEventFilter(filterObj);
An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or forward it to this object. The event filter filterObj receives events via its eventFilter() function. The eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.
If multiple event filters are installed on a single object, the filter that was installed last is activated first.
Here's a KeyPressEater class that eats the key presses of its monitored objects:
class KeyPressEater : public QObject
{
      Q_OBJECT
      ...
      protected:
      bool eventFilter(QObject *obj, QEvent *event);
};
bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
{
      if (event->type() == QEvent::KeyPress) {
            QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
            qDebug("Ate key press %d", keyEvent->key());
            return true;
      } else {
      // standard event processing
      return QObject::eventFilter(obj, event);
}
}




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论