将文件选择器的值设置为调用它的对话框
set value from filepicker to dialog that called it
我有一个调用对话框的操作按钮:
class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.actionLocation.triggered.connect(self.editsettings)
def editsettings(self):
dialog = QDialog()
dialog.ui = Ui_Dialog()
dialog.ui.setupUi(dialog)
dialog.ui.pushButton.clicked.connect(self.openfile)
dialog.exec_()
def openfile(self):
folder = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:/')
# folder value must be set to dialog textedit
对话框工作并在按下按钮时打开文件选择器。选择文件夹时如何设置值。我需要将值放入 textedit
一个简单的解决方案是将 dialog
变量声明为 self
对象的 属性。因此,您可以 class 在所有方法中广泛使用它。
class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.actionLocation.triggered.connect(self.editsettings)
def editsettings(self):
self.dialog = QDialog()
self.dialog.ui = Ui_Dialog()
self.dialog.ui.setupUi(dialog)
self.dialog.ui.pushButton.clicked.connect(self.openfile)
self.dialog.exec_()
def openfile(self):
folder = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:/')
# folder value must be set to dialog textedit
self.dialog.ui.textedit.set_text(folder)
我有一个调用对话框的操作按钮:
class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.actionLocation.triggered.connect(self.editsettings)
def editsettings(self):
dialog = QDialog()
dialog.ui = Ui_Dialog()
dialog.ui.setupUi(dialog)
dialog.ui.pushButton.clicked.connect(self.openfile)
dialog.exec_()
def openfile(self):
folder = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:/')
# folder value must be set to dialog textedit
对话框工作并在按下按钮时打开文件选择器。选择文件夹时如何设置值。我需要将值放入 textedit
一个简单的解决方案是将 dialog
变量声明为 self
对象的 属性。因此,您可以 class 在所有方法中广泛使用它。
class MainPanelManager(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.actionLocation.triggered.connect(self.editsettings)
def editsettings(self):
self.dialog = QDialog()
self.dialog.ui = Ui_Dialog()
self.dialog.ui.setupUi(dialog)
self.dialog.ui.pushButton.clicked.connect(self.openfile)
self.dialog.exec_()
def openfile(self):
folder = QFileDialog.getExistingDirectory(self, 'Select Folder', 'C:/')
# folder value must be set to dialog textedit
self.dialog.ui.textedit.set_text(folder)