qt 键盘事件Key_Left,Right,Up,Down事件捕捉不了,而A,S,D,W能捕捉,为啥啊

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了qt 键盘事件Key_Left,Right,Up,Down事件捕捉不了,而A,S,D,W能捕捉,为啥啊相关的知识,希望对你有一定的参考价值。

if(e->key() == Qt::Key_W)

m_mjcY -= 30;

else if(e->key() == Qt::Key_S)

m_mjcY += 30;

else if(e->key() == Qt::Key_A)

m_mjcX -= 30;

else if(e->key() == Qt::Key_D)

m_mjcX += 30;

else if(e->key() == Qt::Key_Up)

m_hylY -= 30;

else if(e->key() == Qt::Key_Down)

m_hylY += 30;

else if(e->key() == Qt::Key_Left)

m_hylX -= 30;

else if(e->key() == Qt::Key_Right)

m_hylX += 30;

参考技术A This can be a coarse level associated with storage foam in order to encapsulate your feet around comfort

If you would like a few womens or perhaps guys do the job " booties ",nike mercurial football boots, subsequently you might want to seek out Bates " booties " and Carolina " booties ". All these " booties " employ a very good name to get quality and comfort. To get a in close proximity take a look at just what exactly all these " booties " should provide, read the following write-up. Bates " booties " and Carolina " booties ",design football boots, both live up to his or her name associated with dispensing the very best of the footwear creations in order to customers. Your " booties " may also be prepared by special dual-density polymer footbed necessary to soften and pillow a person's every single phase to get comfort everyday. All these footbeds are usually extractible so that you can preserve all of them clear and odor-free.

Bates " booties ",discount football boots, Carolina " booties " are usually a pair of companies around " booties " who have a fantastic name construction business. That they produce " booties " to get toughness and major operation. Each one brand name functions a unique know-how in order to assurance comfort and remarkable operation,sports direct football boots, when suffering from excessive circumstances.
Bates " booties " realize your need to get having a couple " booties " that might let a computer owner in order to dress yourself in all of them to operate also to elsewhere subsequently. Bates? Durashock do the job " booties " are the response to your improving requirement associated with multi-functional " booties ".

All these " booties " are usually performance-driven. There're made when using the full-grain leather-based and abrasion-resistant Cordura uppers in order to stand up to durable beatings and hard troubles in the office. Your soles are usually intrepid plastic outsoles which are slip-and-oil tolerant,Football Boots Shop, to hold an individual on the foot having dependable multi-surface traction,football boots for sale,Thierry Henry, that's important around letting you go walking upon any kind of landscape having comfort and self-belief. Bates " booties " functions your Bates DuraShocks know-how to get a epitome of comfort. The item functions by inserting data compresion pads inside your back heel,cheap adidas football boots, lower leg, and forefoot in order to take up your jolt and come back your energy. Therefore,new footy boots, you should have got much less low energy on the feet and foot,cheap football boots, despite using all of them every day for several working hours.

Carolina " booties " conversely is likewise a vendor associated with working " booties ". It is assignment is usually to supply working footwear-boots associated with course-that is definitely 100% efficient. Your effectiveness implies you feel safe whilst using your " booties ",nike id design football boots, and let you accomplish items you might be necessary within the employment.
Sometimes,buy football boots online, your footwear or perhaps " booties " aren't match to accomplish a few responsibilities mainly positions which are considered challenging. Carolina " booties " are intended to match your differences when using the SE associated with complex design strategies and industry-specific styles. All these strategies put together various components having state-of-the-art and patented know-how.

Your know-how utilized by Carolina " booties " are usually special and efficient. Such as,sale football boots, it is DRYZ,adidas football boots design your own, a forward thinking exclusive method that will take up seepage and converts the item in to a dried out teeth whitening gel,nike football boots sale, makes your insole absorbs your moisture-from sweating-all day time. As a result,adidas football boots, your foot remain dried out. In addition ,footy boots, it functions Iron Toe know-how to satisfy your ASTM benchmarks to get effects and data compresion screening ranking associated with I-75/C-75. Subject to your " booties " manufactured,pink nike football boots, Carolina " booties " utilize it is Electric Risk to safety know-how to ensure a person's boots-and you as well-can stand up to software associated with 18,afl footy boots,pound the soccer in the goal accurately, six hundred volts on 60Hz to get a second without the hazards associated with seapage
You issue amid customers may be the uncomfortableness sensation within the soles after using your " booties " to get some time. Around response to of which problem,mens football boots,perfected, your Carolina " booties " utilize Bed sheets Pillow know-how. As soon as coupled with some other insole methods,nike football boots mercurial, your Carolina " booties " supply the best cushioned comfort inside footwear sector.本回答被提问者采纳
参考技术B 对你的mainWidget调用:
//所有键盘事件将发送到该Widget而不是获得焦点的Widget
mainWidget->grabKeyboard();
参考链接:http://blog.csdn.net/yzzzfree/article/details/6331001

PyQt5-Qt Designer鼠标+键盘事件

重定义鼠标响应+键盘响应事件

一,每个事件都被封装成相应的类:

pyqt中,每个事件类型都被封装成相应的事件类,如鼠标事件为QMouseEvent,键盘事件为QKeyEvent等。而它们的基类是QEvent。

二,基类QEvent的几个重要方法:

accept() 表示事件已处理,不需要向父窗口传播

ignore()表示事件未处理,继续向父窗口传播f

type()返回事件类型,如QtCore.QEvent.MouseButtonPress,一般由基事件调用。因为其它事件已经知道自己的事件类型了。

还有一个自定义事件的注册方法。

三,QMouseEvent鼠标事件:

buttons()  返回哪个鼠标按键被按住了。如Qt.LeftButton

globalPos()  返回鼠标相对屏幕的位置QPoint

pos()  返回鼠标相对处理事件的窗口的位置

四、处理鼠标事件的响应函数(在QWidget及其继承类中):

mousePressEvent(QMouseEvent)  #鼠标点击触发事件  

mouseReleaseEvent(event)  #鼠标释放触发事件

mouseMoveEvent(event)  #鼠标移动触发事件

# 事件。
"""重写鼠标事件,实现窗口拖动。"""
def mousePressEvent(self, event):
    if event.buttons() == Qt.LeftButton:
        self.setCursor(Qt.OpenHandCursor)
        self.parent.m_drag = True
        self.parent.m_DragPosition = event.globalPos()-self.parent.pos()
        event.accept()

def mouseMoveEvent(self, event):
    try:
        if event.buttons() and Qt.LeftButton:
            self.parent.move(event.globalPos()-self.parent.m_DragPosition)#move将窗口移动到指定位置
            event.accept()
    except AttributeError:
        pass

def mouseReleaseEvent(self, event):
    
    if event.button()==Qt.LeftButton:
        self.m_drag = False
        self.unsetCursor()

效果如下:

技术分享图片

重新定义鼠标事件:

"""重定义鼠标单击事件"""
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.lab1.setText("鼠标左键点击!")
            # print(event.pos().x(),event.pos().y())
        if event.button() == Qt.RightButton:
            self.lab1.setText("鼠标右键点击!")

    """当鼠标左键点击拖动时触发事件,有无if判断条件效果都一样"""
    def mouseMoveEvent(self, event):
        # if event.buttons() == Qt.LeftButton:
        #     # print(type(event.pos().x()))    #<class ‘int‘>
        #     self.lab2.setText(str(event.pos().x())+","+str(event.pos().y()))
        self.pos = event.pos()
        print(self.pos)
        self.lab2.setText(str(event.pos().x()) + "," + str(event.pos().y()))
        self.update()

完整代码:

技术分享图片
 1 from PyQt5.QtCore import Qt
 2 from PyQt5.QtGui import (QPainter, QColor, QPen)
 3 import sys
 4 from PyQt5.QtWidgets import (QApplication,QWidget,QLabel)
 5 
 6 class Example(QWidget):
 7     def __init__(self):
 8         super(Example, self).__init__()
 9         self.initUi()
10         #默认情况下禁用鼠标跟踪, 如果启用鼠标跟踪,即使没有按钮被按下,小部件也会接收鼠标移动事件。
11         #当然你也可以不写,只需要在执行的过程中按照鼠标左键也行
12         self.setMouseTracking(True)
13 
14     def initUi(self):
15         self.setGeometry(400,300,400,300)
16         self.setWindowTitle("键盘响应事件")
17         self.lab1 = QLabel("方向",self)
18         self.lab1.setGeometry(200,150,100,100)
19         self.lab2 = QLabel("显示鼠标坐标", self)
20         self.lab2.setGeometry(200, 80, 100, 100)
21 
22     """重定义键盘事件"""
23     def keyPressEvent(self,e ):
24         if e.key() == Qt.Key_Up:
25             self.lab1.setText("")
26         elif e.key() == Qt.Key_Down:
27             self.lab1.setText("")
28         elif e.key() == Qt.Key_Left:
29             self.lab1.setText("")
30         else:
31             self.lab1.setText("")
32 
33     """重定义鼠标单击事件"""
34     def mousePressEvent(self, event):
35         if event.button() == Qt.LeftButton:
36             self.lab1.setText("鼠标左键点击!")
37             # print(event.pos().x(),event.pos().y())
38         if event.button() == Qt.RightButton:
39             self.lab1.setText("鼠标右键点击!")
40 
41     """当鼠标左键点击拖动时触发事件,有无if判断条件效果都一样"""
42     def mouseMoveEvent(self, event):
43         # if event.buttons() == Qt.LeftButton:
44         #     # print(type(event.pos().x()))    #<class ‘int‘>
45         #     self.lab2.setText(str(event.pos().x())+","+str(event.pos().y()))
46         self.pos = event.pos()
47         print(self.pos)
48         self.lab2.setText(str(event.pos().x()) + "," + str(event.pos().y()))
49         self.update()
50 
51 
52 
53 if __name__ == __main__:
54     app = QApplication(sys.argv)
55     ex = Example()
56     ex.show()
57     sys.exit(app.exec_())
重定义鼠标响应+键盘响应

 

所有的QT键盘事件代码如下:

https://pan.baidu.com/s/1Brry6fkUcxaP-uOdukD8Ng

以上是关于qt 键盘事件Key_Left,Right,Up,Down事件捕捉不了,而A,S,D,W能捕捉,为啥啊的主要内容,如果未能解决你的问题,请参考以下文章

Vue的键盘事件

Vue中监听键盘事件

vue--阻止冒泡、默认行为、键盘事件

Vue之自定义按键及指令

qt的键盘事件

qt中重写键盘事件冲突了