PyQt4 File select widget

后端 未结 3 544
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条回答
  •  旧时难觅i
    2021-02-07 03:12

    You can use method getOpenFileName() in QFileDialog Class.

    QFileDialog.getOpenFileName() will return the file path and the selected file type

    I got this : ('C:/Users/Sathsara/Desktop/UI/Test/test.py', 'All Files (*)')

    To get only the file path use QFileDialog.getOpenFileName()[0]


    Sample code:

    def selectFile():
       print(QFileDialog.getOpenFileName()[0])
    
    
    dlg.locationBtn.clicked.connect(selectFile)
    

提交回复
热议问题