2016-10-03 28 views
0

我有一个操作按钮调用,我已经做了一个对话框:设定值从filepicker到对话框,把它称为

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

回答

0

一个简单的解决方案是声明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)