2

I used QT Designer to build a custom form for attribute entry. One of the attributes is for storing a file path of a permit document as a string. With the auto-generated forms, there was a URL selector which worked fine. However, I can't seem to figure out how to do the same thing with my custom form UI that I made in QT designer. As it stands right now, users will have to manually enter the file path by copy and pasting but ideally I would like to give them the same functionality as the dialog box that appears when you use the url selector.

I looked around at QFileDialog but most of what I get is form coding in applications and I'm not sure how to finesse it into working with a layer form UI.

2

I wrote this code to accept a QLineEdit object so that I could connect this same function to multiple buttons and pass in the appropriate field that I wanted to have filled out.

I connected it with: someButton.clicked.connect(selectFile(someQLineEditObject))

When you click the button, a dialog box opens and fills the QLineEdit with the path to the selected file.

#opens a file selection dialog when browse is clicked
def selectFile(item):
    #create an instance of QFileDialog
    fileDlg = QFileDialog()
    #Sets the field text as the selected file path
    item.setText(fileDlg.getOpenFileName())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.