Qt Designer¶
PythonQwt ships a Qt Designer plugin which makes a 2D plotting widget
(qwt.qtdesigner.QwtPlotWidget, a thin qwt.QwtPlot subclass)
available directly inside Qt Designer’s widget box, in the “PythonQwt” group.
Installing the plugin¶
The plugin file qwtplugin.py lives in the qtdesigner directory at the
root of the PythonQwt source tree. To make it available in Qt Designer, add
that directory to the PYQTDESIGNERPATH environment variable before
starting Qt Designer:
# Linux/macOS
export PYQTDESIGNERPATH=<path to PythonQwt>/qtdesigner
designer
rem Windows
set PYQTDESIGNERPATH=<path to PythonQwt>\qtdesigner
designer
Note
Qt Designer custom widget plugins require PyQt5 or PyQt6. PySide6 does not
expose QPyDesignerCustomWidgetPlugin.
Loading a .ui file at runtime¶
The qwt.qtdesigner module provides helper functions to load or compile
.ui files embedding qwt.qtdesigner.QwtPlotWidget widgets:
from qwt.qtdesigner import loadui
FormClass = loadui("myform.ui")
form = FormClass()
form.plotwidget.setTitle("Loaded from Qt Designer")
Reference¶
Qt Designer¶
The qwt.qtdesigner module provides helpers to integrate qwt
widgets into Qt Designer:
QwtPlotWidget is a thin qwt.QwtPlot subclass exposing the
standard Qt widget constructor (__init__(self, parent=None)). It is the
widget promoted by the Qt Designer plugin, so that the code generated by
uic (e.g. QwtPlotWidget(parent=...) with PyQt6) instantiates it
correctly. qwt.QwtPlot itself keeps its historical constructor.
Note
Qt Designer custom widget plugins rely on
QtDesigner.QPyDesignerCustomWidgetPlugin, which is only available
with PyQt5/PyQt6. PySide6 does not expose this class.
- class qwt.qtdesigner.QwtPlotWidget(parent=None)[source]¶
qwt.QwtPlotwidget with the standard Qt constructor.This subclass is meant to be promoted in Qt Designer: unlike
qwt.QwtPlot(whose constructor accepts the historicalQwtPlot([title], [parent])overloads), it exposes the conventional__init__(self, parent=None)signature expected by the code generated byuic(notably PyQt6, which usesQwtPlotWidget(parent=...)).- Args:
parent: Parent widget
- qwt.qtdesigner.loadui(fname: str, replace_class: str | None = None)[source]¶
Return Widget or Window class from a Qt Designer
.uifile.When a promoted widget inherits from a class that is not known to the
uicparser (i.e. not a standard Qt widget),loadUiTypefails to resolve the widget hierarchy. Passing the offending base class name asreplace_classneutralizes it by substitutingQFrame(the base class ofqwt.QwtPlot) before the file is parsed.For a plain
qwt.QwtPlotwidget (which already inherits fromQFrame), no replacement is required andreplace_classcan be left toNone.- Args:
fname: Path to the
.uifile replace_class: Base class name to replace byQFrame, orNoneto load the file unchanged
- Returns:
The generated form class
- qwt.qtdesigner.compileui(fname: str, replace_class: str | None = None) None[source]¶
Compile a Qt Designer
.uifile into a Python module.- Args:
fname: Path to the
.uifile replace_class: Base class name to replace byQFrame, orNoneto compile the file unchanged
- qwt.qtdesigner.create_qtdesigner_plugin(group: str, module_name: str, class_name: str, icon: str | QIcon | None = None, tooltip: str = '', whatsthis: str = '')[source]¶
Return a custom Qt Designer plugin class.
- Args:
group: Name of the group the widget belongs to in Qt Designer module_name: Name of the module where the widget class is defined class_name: Name of the widget class icon: Icon shown in Qt Designer (path to an image file or
QtGui.QIconinstance)tooltip: Tool tip shown in Qt Designer whatsthis: “What’s this” help text shown in Qt Designer
- Returns:
A
QtDesigner.QPyDesignerCustomWidgetPluginsubclass
Example:
Plugin = create_qtdesigner_plugin( group="PythonQwt", module_name="qwt.qtdesigner", class_name="QwtPlotWidget", )