Calling custom class in .ui file fails

前端 未结 1 1854
面向向阳花
面向向阳花 2021-01-14 15:59

I get this error when I try to refer to my custom class from .ui file. What\'s wrong with what I do?

\"QFormBuilder was unable to create a cust         


        
相关标签:
1条回答
  • 2021-01-14 16:16

    In theory, to have your custom widget work you should only have to call:

    loader.registerCustomWidget(TimelinePane)
    

    before calling loader.load(). You need to add the relevant import statements, in your case:

    from timeline_pane import TimelinePane
    

    However, I just tested this with PySide 1.1.2 on Ubuntu 12.04 x86_64, and it caused a segfault. YMMV, so please test.

    I ended up implementing this workaround: http://www.mail-archive.com/pyside@qt-project.org/msg00306.html

    In short, override the QUiLoader's creteWidget() method, and if the class_name of the widget is not in self.availableWidgets(), instantiate it yourself according to the customWidgets instance variable that you've added.

    BTW, you can also make use of the right-click "Promote To" functionality in the Qt Designer instead of editing the ui file directly.

    0 讨论(0)
提交回复
热议问题