Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';如果keyPressEvent处于打开状态,则在QlineEdit中键入_Python_Pyqt4 - Fatal编程技术网

Python Can';如果keyPressEvent处于打开状态,则在QlineEdit中键入

Python Can';如果keyPressEvent处于打开状态,则在QlineEdit中键入,python,pyqt4,Python,Pyqt4,我的QLineEdit有问题,如果我在代码中启用了keyPressEvent,那么我就无法在QLineEdit中键入任何内容 class SearchBox(gui.QLineEdit): def __init__(self, parent=None): super(SearchBox, self).__init__(parent) self.setWindowTitle("Explorer") self.setGeometry(500,

我的QLineEdit有问题,如果我在代码中启用了keyPressEvent,那么我就无法在QLineEdit中键入任何内容

class SearchBox(gui.QLineEdit):
    def __init__(self, parent=None):
        super(SearchBox, self).__init__(parent)

        self.setWindowTitle("Explorer")
        self.setGeometry(500,500,400,40)
        font = gui.QFont()
        font.setPointSize(15)
        self.setFont(font)

    # if i disable this function then it works..
    def keyPressEvent(self, event):
        if event.key() == core.Qt.Key_Escape:
            self.close()
        if event.key() == core.Qt.Key_Enter:
            print self.text()
            self.close()
有人能帮我做这个吗。。
谢谢。

如果你没有调用基类的
keyPressEvent
,它怎么知道某个键被按下了

def keyPressEvent(self, event):
    if event.key() == core.Qt.Key_Escape:
        self.close()
    if event.key() == core.Qt.Key_Enter:
        print self.text()
        self.close()
    else:
        super(SearchBox, self).keyPressEvent(event)
以下文件中也提到了这一点:

如果重新实现此处理程序,则调用 如果不按键操作,则基类实现