What's a good way to make a folder selection menu in a docker?

I need to add a folder selection menu in a docker i’m making (kinda like the folder selection in the recorder docker, but the easier the better honestly). I can’t exactly figure out how this QFileDialog thing works.

currently, i have a browse button and a lineEdit to display the folder path (i don’t know if this is the best setup, especially the lineEdit). then the browse button calls a QFileDialog window, that then updates the lineEdit.

I can’t for the life of me get this setup to work, so I think now that my design itself is fundamentally flawed. There HAS to be a better way of doing this.

Hi

Here a small example about how to use save/load file dialog

from krita import *
from PyQt5.Qt import *


def saveFile():
    fileName, dummy = QFileDialog.getSaveFileName(None, 'Save file', '', "All files (*.*);;Text files (*.txt);;Png Files (*.png)")
    if fileName != '':
        print("Save to:", fileName)
    else:
        print("Save to: cancelled!")

def loadFile():
    fileName, dummy = QFileDialog.getOpenFileName(None, 'Load file', '', "All files (*.*);;Text files (*.txt);;Png Files (*.png)")
    if fileName != '':
        print("Load from:", fileName)
    else:
        print("Load from: cancelled!")


btnSave = QPushButton("Save")
btnSave.clicked.connect(saveFile)
btnLoad = QPushButton("Load")
btnLoad.clicked.connect(loadFile)

layout=QHBoxLayout()
layout.addWidget(btnSave)
layout.addWidget(btnLoad)

dlg=QDialog()
dlg.setLayout(layout)
dlg.exec()

Grum999

thanks again bro, ill try this

edit: is there anyway to select only folders?
nvm, found it, its QFileDialog.getExistingDirectory()

This is how I wrote mine

    def Folder_Open(self):
         file_dialog = QFileDialog(QWidget(self))
         file_dialog.setFileMode(QFileDialog.DirectoryOnly)
         directory_path = file_dialog.getExistingDirectory(self, "Select Directory")
         directory_path = os.path.normpath( directory_path )
         if (directory_path != "" and directory_path != "." and self.directory_path != directory_path):
             self.Folder_Changer(directory_path)

With directory:

from krita import *
from PyQt5.Qt import *


def chooseDirectory():
    fileName = QFileDialog.getExistingDirectory(None, 'Choose directory', '', QFileDialog.ShowDirsOnly)
    if fileName != '':
        print("Directory selected:", fileName)
    else:
        print("Directory selected: cancelled!")


def saveFile():
    fileName, dummy = QFileDialog.getSaveFileName(None, 'Save file', '', "All files (*.*);;Text files (*.txt);;Png Files (*.png)")
    if fileName != '':
        print("Save to:", fileName)
    else:
        print("Save to: cancelled!")

def loadFile():
    fileName, dummy = QFileDialog.getOpenFileName(None, 'Load file', '', "All files (*.*);;Text files (*.txt);;Png Files (*.png)")
    if fileName != '':
        print("Load from:", fileName)
    else:
        print("Load from: cancelled!")


btnChooseDir = QPushButton("Choose directory")
btnChooseDir.clicked.connect(chooseDirectory)
btnSave = QPushButton("Save")
btnSave.clicked.connect(saveFile)
btnLoad = QPushButton("Load")
btnLoad.clicked.connect(loadFile)

layout=QHBoxLayout()
layout.addWidget(btnChooseDir)
layout.addWidget(btnSave)
layout.addWidget(btnLoad)

dlg=QDialog()
dlg.setLayout(layout)
dlg.exec()