I've been going around in circles with this for a few hours so hopefully someone can help. I am familiar with VB, C# but not Python - and struggling to do something fairly simple.
I have created a form using QT Designer. On this form are a QlistView widget and a "Browse..." button. I want to be able to select files by clicking on the button, and list these in the QlistView. Should be easy enough.
In languages I am familiar with I would reference the QlistView object using syntax like [form name].[control name] but cannot do that here, apparently.
I have got
self.dlg set to the form itself.
The list widget is a QlistWidget, with the name
I am using the following code to handle the button click:
def handleBrowseButton(self): pth =os.path.normpath('E:') filter = "TXT (*.txt)" file_name = QtGui.QFileDialog() file_name.setFileMode(3) # 3=existing files names = file_name.getOpenFileNames(None, "Open files", pth, filter) if not names: print "CANCELLED" return l = self.dlg.findChild(listWidget)
...but getting a bit stuck at the last bit. Do I have to use findChild / findChildren / something else??
The above code does run, so I haven't got a problem getting to that point. The issue is just how to set a reference to the listWidget object on the form in order to refer to it from that point on.
My intention is to set 'l' to refer to the listWidget and then do something like