Hello everyone,
I am trying to implement a simple program where I can track the evolution of the chemical composition of my calculations. With PyQT5, a similar workflow worked out back in the day. However, I’m using PySide6 for my new “project”, and it’s not working out. The problem is that the MplWidget class is not being called while initializing the view, so the QWidget stays empty, and no axis will be displayed. The „widget_evolution“ is still a QWidget, not the self-defined one.
Firstly, I’m defining the QWidget via the QtDesigner, and I am promoting it to the self-defined MplWidget class (I already tried to use just mplwidget but also mplwidget.py or mplwidget.h as the header filename).
The UI file contains necessary information about the MplWidget:
<widget class="MplWidget" name="widget_evolution" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(174, 174, 174);</string>
</property>
</widget>
and
<customwidgets>
<customwidget>
<class>MplWidget</class>
<extends>QWidget</extends>
<header>mplwidget</header>
<container>1</container>
</customwidget>
</customwidgets>
All files (mplwidget.py, post_processing.py and post-processing.ui) are located in the same folder.
The MplWidget class is defined inside the mplwidget.py and contains following code:
from PySide6.QtWidgets import QWidget, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT
class NavigationToolbar(NavigationToolbar2QT):
# only display the buttons we need
toolitems = [t for t in NavigationToolbar2QT.toolitems if
t[0] in ('Home', 'Back', 'Forward', 'Zoom', 'Pan','Save')]
class MplWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvasQTAgg(Figure())
self.canvas.axes = self.canvas.figure.add_subplot(111)
self.toolbar = NavigationToolbar(self.canvas, self)
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.toolbar)
vertical_layout.addWidget(self.canvas)
self.setLayout(vertical_layout)
Finally the UI file has been loaded by the PostProcessingUI module:
class PostProcessingUI(QMainWindow):
def __init__(self):
super().__init__()
loader = QUiLoader()
self.ui = loader.load(
os.path.join(basedir, "post-processing.ui"), None
)
Every help would be appreciated. Many thanks in advance!