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".
QStackedWidget can be used to create a user interface similar to the one provided by QTabWidget . It is a convenience layout widget built on top of the QStackedLayout class. Like QStackedLayout , QStackedWidget can be constructed and populated with a number of child widgets (“pages”):
PySide2 Tutorial — Creating applications with Qt Designer The good news is that Qt comes with a graphical editor — Qt Designer — which contains a drag-and-drop UI editor. Using Qt Designer you can define your UIs visually and then simply hook up the application logic later.
The QVBoxLayout class lines up widgets vertically. This class is used to construct vertical box layout objects. See QBoxLayout for details.
I got it figured out, my actual code is slightly different then the simplified example I gave. My actual code is more like this:
/PythonModuleRoot/Ui/MainUi.py
/PythonModuleRoot/Ui/MainUi.ui
/PythonModuleRoot/Ui/Widgets/CustomWidget.py
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/[email protected]/msg17893.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With