PyQt4 File select widget

后端 未结 3 466
Happy的楠姐
Happy的楠姐 2021-02-07 02:18

I want to make a QT4 (using QT designer) dialog, that contains a part where a file has to be selected.

Now, I know QFileDialog exists, and I can program something that d

3条回答
  •  渐次进展
    2021-02-07 03:09

    There is no file dialog available from the Qt designer as far as I know. But you can easily do it with a few lines of code.

    Assuming you have a simple button called pushButton and the path should be stored in lineEdit.

    def selectFile():
        lineEdit.setText(QFileDialog.getOpenFileName())
    
    pushButton.clicked.connect(selectFile)
    

    [edit]Just wondering though, are you using KDE by any chance? If so, than you can use the KUrlRequester for this. It can easily be configured to support anything from files to urls to directories.

提交回复
热议问题