-1

I'm pretty new with Qt in Python, and I need to know how could I get from a file dialog one directory path and show it in a text box inside my ui.

class ControllerLibraryUI(QtWidgets.QDialog):
    def __init__(self):
        super(ControllerLibraryUI, self).__init__()
        self.setWindowTitle('Controller Window')
        self.buildUI()

    def buildUI(self):
        layout = QtWidgets.QVBoxLayout(self)
        textWidget = QtWidgets.QWidget()
        textLayout = QtWidgets.QHBoxLayout(textWidget)
        layout.addWidget(textWidget)
        self.saveNameField = QtWidgets.QTextEdit()
        textLayout.addWidget(self.saveNameField)
        btnWidget = QtWidgets.QWidget()
        btnLayout = QtWidgets.QHBoxLayout(btnWidget)
        layout.addWidget(btnWidget)
        importBtn = QtWidgets.QPushButton('Import')
        importBtn.clicked.connect(self.load)
        btnLayout.addWidget(importBtn)
        closeBtn = QtWidgets.QPushButton('Close')
        closeBtn.clicked.connect(self.close)
        btnLayout.addWidget(closeBtn)

    def load(self ):
            filename = QtWidgets.QFileDialog.getOpenFileName()[0]
            print filename
    def showUI():
        try:
            ui.close()
        except:
            ui = ControllerLibraryUI()
            ui.show()
            return ui

ui = showUI()

This is the basic concept.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

for the file dialog :

directory = QtGui.QFileDialog.getExistingDirectory(self, 'Select directory')

and then you assign the directory variable to the setText method from your text box

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
DrWeeny
  • 2,487
  • 1
  • 14
  • 17