[PyQt] uic.loadUi and package argument
Fredrik Averpil
fredrik.averpil at gmail.com
Thu Aug 4 22:12:30 BST 2016
Hi,
I’d like to load a .ui file and use a custom widget in it without importing
a package from disk. I’m trying to achieve this like so:
class MyCustomClass(QtWidgets.QPushButton):
def __init__(self, *args):
QtWidgets.QPushButton.__init__(self, *args)
sys.modules['mycustompackage'] = MyCustomClass
uic,loadUi('my_ui.ui', self, 'mycustompackage')
However, the error I’m getting is this:
AttributeError: type object 'MyCustomClass' has no attribute 'MyCustomWidget'
Any ideas on whether I can make this work at all - and if so how?
Here’s my .ui:
<?xml version="1.0" encoding="UTF-8"?><ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="MyCustomWidget" name="customWidget">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>MyCustomWidget</class>
<extends>QPushButton</extends>
<header>MyCustomClass</header>
</customwidget>
</customwidgets>
<resources/>
<connections/></ui>
Regards,
Fredrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160804/58d17944/attachment-0001.html>
More information about the PyQt
mailing list