IsaacS
IsaacS

Reputation: 3611

How to read widgets in .ui file with PySide

I'm trying to access Qt elements that are loaded via .ui file. However I'm getting error:

AttributeError: 'TreeviewWidgetSelectProve' object has no attribute '_treeview'

Full python code and .ui file are available in those links respectively. Code snippet:

    ui_file_path = os.path.join(
        '/home/userdaze/pyside_test', 'resource', 'treeview.ui')

    loader = QUiLoader(self)
    ui_file = QFile(ui_file_path)
    self._widget_top = loader.load(ui_file, self)

    self._treeview = self._widget_top.findChild(QTreeView, '_treeview')
    self._treeview.setModel(self._std_model)

Whether I use findChild suggested in this thread doesn't change the situation. It returns NoneType if in use.

What is wrong? Thank you!

python-pyside 1.1.1-3 on Ubuntu Quantal

Upvotes: 0

Views: 398

Answers (1)

Dorian Scholz
Dorian Scholz

Reputation: 166

I'm afraid your .ui file is broken. Have you tried opening it in the QtDesigner? When I do that it reports an error. So I recreated the file with QtDesigner (just a QMainWindows with a QTreeView) and your problem disappears.

There are plenty of other problems though:

Upvotes: 2

Related Questions