简体   繁体   English

pyside-如何捕获大写字母(KeyEvent)?

[英]pyside - how to capture capital letter (KeyEvent)?

I have understood that letters to capture the event is used keyPressEvent . 我了解到,捕获事件的字母是使用keyPressEvent

def iniciar(self):
    self.resize(730, 500)
    self.setFixedSize(730, 500)
    self.center()
    self.setWindowTitle('Practico 1')
    self.show() 

def center(self):
    qr = self.frameGeometry()
    cp = QtGui.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())

def keyPressEvent(self, e):
    if e.key() == QtCore.Qt.Key_A:
        QtGui.QMessageBox.information(self, 'pressed', 'you pressed the letter "a"')                

This way I capture letters either in uppercase or lowercase, but how should I verify a capital letter has been pressed? 通过这种方式,我可以捕获大写或小写字母,但是应该如何验证是否已按下大写字母呢?

You can check uppercase using modifiers. 您可以使用修饰符检查大写字母。 For instance with 例如与

if e.key() == QtCore.Qt.Key_A and (e.modifiers() & QtCore.Qt.SHIFT):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在大写字母前添加新行? - How to add a new line before a capital letter? 如何改变python中大写字母的单词的第i个字母? - how to change ith letter of a word in capital letter in python? 当且仅当前一个字母不是大写字母时,才如何在大写字母前插入空格? - How do I insert space before capital letter if and only if previous letter is not capital? 如何在Python中获取第一个大写字母,然后再获取每个不跟另一个大写字母的字母? - How to get the first capital letter and then each that isn't followed by another capital letter in Python? 如何在python中要求输入字符串的大写字母和数字? - How to require a capital letter and a number for an input string in python? 如何找到一个单词 - 第一个字母大写,其他字母小写 - How to find a word - First letter will be capital & other will be lower 如何在没有空格的情况下对大写字母进行正则表达式| Python 3 - How to regex Capital Letter without space before | Python 3 如何查找单词 - 第一个字母大写,其他字母小写 - How to find a words - First letter will be capital & other will be lower 如何使用正则表达式从 NLTK 语料库中查找大写字母单词? - How to find a capital letter words from an NLTK corpus using regex? 如何识别 Python 中是否至少有一个大写字母? - How can I identify if there is, at least, one capital letter in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM