我是PyQt的新手.我在QtDeveloper中设计了一个有三个控件的表单.一个按钮,一个组合框和一行编辑.我的ui表单中的行编辑小部件的名称是myLineEdit.我想知道哪个Qwidget得到了关注(QLineEdit或QComboBox).我实现从互联网获得的代码.代码运行时,会创建一个单独的行编辑,它可以正常工作.但我想将focusInEvent提供给以.ui格式创建的myLineEdit小部件.我的代码是给出的.请帮忙.
class MyLineEdit(QtGui.QLineEdit):
def __init__(self, parent=None):
super(MyLineEdit, self).__init__(parent)
def focusInEvent(self, event):
print 'focus in event'
self.clear()
QLineEdit.focusInEvent(self, QFocusEvent(QEvent.FocusIn))
class MainWindow(QtGui.QMainWindow,Ui_MainWindow):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.myLineEdit = MyLineEdit(self)
Run Code Online (Sandbox Code Playgroud)