PySide and Python - How to browse a folder and write the file name?
Question: I would like to press a button and than open a file browser and write down
selected file in a label. I have this function which I call when the button is
pressed:

    
    
        @Slot()
        def browse_folder(self):
            self.fname = QtGui.QFileDialog.getOpenFileName()
            self.statusLabel.setText(self.fname)
    

However, I get an error:

    
    
    TypeError: 'PySide.QtGui.QLabel.setText' called with wrong argument types:
      PySide.QtGui.QLabel.setText(unicode, unicode)
    Supported signatures:
      PySide.QtGui.QLabel.setText(unicode)
    

How do I convert `self.fname`, which holds selected file name, as unicode?


Answer: The PySide docs are not brilliant on this. But the easiest way to answer this
sort of question is to build a little test harness. Something like:

    
    
    from PySide import QtCore,QtGui
    
    def do_file():
        fname = QtGui.QFileDialog.getOpenFileName()
        print fname
    
    app = QtGui.QApplication([])
    
    button = QtGui.QPushButton("Test File")
    button.clicked.connect(do_file)
    button.show()
    
    app.exec_()
    

Running this a little bit will show you that the static `getOpenFileName`
method returns a tuple consisting of the filename first and the chosen filter
second. For example, by default, on my system this returns
`('C:/Users/Myname/Documents/filename', 'All Files (*.*)')`.

So you then need to extract the first element of the tuple before calling
`setText`.

