对不起,标题是满嘴巴,但基本上我在这里要做的是我有3个按钮,它们都打开QFileDialog供用户选择要使用的文件。由于动作相同,我想对所有 3 个使用相同的功能,但根据按下的按钮,我需要更新不同的 QLineEdit 以反映 GUI 中的文件路径。我该如何实现呢?
#Create the prompt for user to load in the q script to use
self.qFileTF = QtGui.QLineEdit("Choose the q script file to use")
self.qFileButton = QtGui.QPushButton("Open")
self.qFileButton.setFixedSize(100,27)
self.fileLayout1.addWidget(self.qFileTF)
self.fileLayout1.addWidget(self.qFileButton)
#Create the prompt for user to load in the light house file to use
self.lhFileTF = QtGui.QLineEdit("Choose the light house file to use")
self.lhButton = QtGui.QPushButton("Open")
self.lhButton.setFixedSize(100,27)
self.fileLayout2.addWidget(self.lhFileTF)
self.fileLayout2.addWidget(self.lhButton)
#Create the prompt for user to choose to reference an older version of q script
self.oldQCB = QtGui.QCheckBox("Reference an older version Q script")
self.oldQTF = QtGui.QLineEdit("Choose the q script file to use")
self.oldQTF.setEnabled(False)
self.oldQButton = QtGui.QPushButton("Open")
self.oldQButton.setEnabled(False)
self.oldQButton.setFixedSize(100,27)
self.fileLayout3.addWidget(self.oldQTF)
self.fileLayout3.addWidget(self.oldQButton)
self.connect(self.qFileButton, QtCore.SIGNAL("clicked()"), self.loadFile)
self.connect(self.lhButton, QtCore.SIGNAL("clicked()"), self.loadFile)
self.connect(self.oldQButton, QtCore.SIGNAL("clicked()"), self.loadFile)
def loadFile(self):
selFile = QtGui.QFileDialog.getOpenFileName()
if self.qFileButton:
self.qFileTF.setText(selFile)
elif self.lhFileTF:
self.lhFileTF.setText(selFile)
else:
self.oldQTF.setText(selFile)