Important: Please read the Qt Code of Conduct -

QtCharts in Qt Designer

  • Hi everybody,
    again I am facing a problem with adding an external element to Qt Designer via promoting basic classes.
    Now I have a problem with promoting QtChart...
    May be this is just some problem with my understanding of how the promotion works, but I really wasn't able to find any clear instructions on how to do it. May be I am missing some important insight.
    With my setup I get an error:

    ModuleNotFoundError: No module named 'QtCharts'

    Below some basic code example, the according .ui file and a screenshot of installed packages (to assure you that PyQt5 and PyQtChart do have the the same version)

    When trying to promote the GraphicsView class I was referring to the following answer on stackoverflow: (Option 1)
    The only thing I didn't do is to add QT += charts in the .pro, because I don't quite get what is meant by that.

    import sys, os
    from PyQt5.uic import loadUi
    from PyQt5.QtWidgets import QApplication, QMainWindow
    CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
    class MainWindow(QMainWindow):
        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)
            path = os.path.join(CURRENT_DIRECTORY, 'GUI', 'main.ui')
            self.w = loadUi(path)
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        w = MainWindow()
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
      <property name="windowTitle">
      <widget class="QWidget" name="centralwidget">
       <widget class="QChartView" name="graphicsView">
        <property name="geometry">
      <widget class="QMenuBar" name="menubar">
       <property name="geometry">
      <widget class="QStatusBar" name="statusbar"/>
      <buttongroup name="abc"/>

    2021-01-29 10_09_43-Settings.png

    Thanks a lot in advance for all your answers!

Log in to reply