0
我是PyQt的新手。我在QtDeveloper中设计了一个有三个控件的表单。一个按钮,一个组合框和一行编辑。我的UI格式中的行编辑小部件的名称是myLineEdit。我想知道哪个Qwidget获得焦点(QLineEdit或QComboBox)。我执行从互联网上获得的代码。代码运行时,会创建一个单独的行编辑,并且工作正常。但是我想将focusInEvent赋给以.ui形式创建的myLineEdit小部件。我的代码给出。请帮忙。如何知道用户界面中的哪个qwidget获得了pyqt的焦点
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)
它的工作就像一个魅力。谢谢亲爱的。 –