将值从文件选择器设置为调用它的对话框
Posted
技术标签:
【中文标题】将值从文件选择器设置为调用它的对话框【英文标题】:set value from filepicker to dialog that called it 【发布时间】:2016-10-03 11:01:05 【问题描述】:我有一个操作按钮,可以调用我制作的对话框:
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
【问题讨论】:
【参考方案1】:一个简单的解决方案是将dialog
变量声明为self
对象的属性。因此,您可以在所有方法中广泛使用它。
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)
【讨论】:
以上是关于将值从文件选择器设置为调用它的对话框的主要内容,如果未能解决你的问题,请参考以下文章