当前位置:编程学习 > wap >>

依然是QPushButton保持按压的问题

--------------------编程问答-------------------- 等大神~ --------------------编程问答-------------------- 因为失去焦点了。 --------------------编程问答-------------------- 为啥你要这样做? --------------------编程问答-------------------- 因为……因为已经这么做了,按下松开按钮做得事是和硬件的通讯,还涉及到协议,想要更改协议已经很难了……

所以现在就是面对这个问题,软件上如何解决…… --------------------编程问答-------------------- 正常情况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);
     }
 } --------------------编程问答-------------------- 您可以会获得很多event,挑选一下吧。 --------------------编程问答-------------------- 嗯,我有空会试一下的,谢谢!
补充:移动开发 ,  Qt
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,