I’m using PyQt and trying to promote a widget in QtDesigner. I’m able to get it working if I specify the full module path, in the “Header file” field, to the file that contains my widget sub-class.
Is there a better way to promote a widget in QtDesigner to a PyQt widget without having to specify the full module path?
Here’s an example to hopefully illustrate what I’m talking about:
/PythonModuleRoot/Ui/MainUi.py
from PyQt4 import QtCore, QtGui, uic
class MainUi(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.ui = uic.loadUi(os.path.join(os.path.dirname(__file__), 'MainUi.ui'), self)
/PythonModuleRoot/Ui/CustomWidget.py
from PyQt4 import QtCore, QtGui, uic
class CustomWidget(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
/PythonModuleRoot/Ui/MainUi.ui
In MainUi.ui I promote a widget and set the Header file field to: “PythonModuleRoot.Ui.CustomWidget”.
I got it figured out, my actual code is slightly different then the simplified example I gave. My actual code is more like this:
So I just needed to change the contents of Header file to be how MainUi would import CustomWidget, so: “Widgets.CustomWidget”. This article pointed me in the right direction: http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg17893.html