Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to show a QChartView embedded in a QDialog
Forum Updated to NodeBB v4.3 + New Features

How to show a QChartView embedded in a QDialog

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 276 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josef Michael Laub
    wrote on last edited by
    #1

    I'm trying to bind a QChartView to a QDialog object so it doesn't have to be displayed in the main window.
    The problem is that QDialog doesn't provide the setCentralWidget function!
    How do I bind the QChartView object to the QDialog object? I found online that I should do this using an "AddChild" function, but I can't find that either.
    Since I'm a Qt beginner, I would appreciate a simple explanation with sufficiently simple code.

    class Statistics(QDialog):
        def __init__(self,filename,right):
            super().__init__(self)
            self.statistics={}
            self.filename=filename
            self.right=right
            
            self.readStatistics()
            if(len(self.statistics.get(self.filename))==10):
               del self.statistics[self.filename]
            self.statistics.setdefault(self.filename,[]).append(self.right)
            self.charts=self.statistics.get(self.filename)
            self.writeStatistics()
    
            self.set0 = QBarSet("Right Input")
            self.set0.append(self.charts)
            self._bar_series = QBarSeries()
            self._bar_series.append(self.set0) 
            self.chart = QChart()
            self.chart.addSeries(self._bar_series)
            self.chart.setTitle("Learn Progress for Unit: "+filename)
            self.categories = ["Try 1", "Try 2", "Try 3", "Try 4", "Try 5", "Try 6", "Try 7", "Try 8", "Try 9", "Try 10"]
            self._axis_x = QBarCategoryAxis()
            self._axis_x.append(self.categories)
            self.chart.addAxis(self._axis_x, Qt.AlignBottom)
            self._bar_series.attachAxis(self._axis_x)
            self._axis_x.setRange("Try 1", "Try 10")
            self._axis_y = QValueAxis()
            self.chart.addAxis(self._axis_x, Qt.AlignLeft)
            self._bar_series.attachAxis(self._axis_y)
            self._axis_y.setRange(0, 100)
            self.chart.legend().setVisible(True)
            self.chart.legend().setAlignment(Qt.AlignBottom)
            self._chart_view = QChartView(self.chart)
            self._chart_view.setRenderHint(QPainter.RenderHint.Antialiasing)
            **self.setCentralWidget(self._chart_view)**
    
    

    I ask for help!!!

    JonBJ 1 Reply Last reply
    0
    • J Josef Michael Laub

      I'm trying to bind a QChartView to a QDialog object so it doesn't have to be displayed in the main window.
      The problem is that QDialog doesn't provide the setCentralWidget function!
      How do I bind the QChartView object to the QDialog object? I found online that I should do this using an "AddChild" function, but I can't find that either.
      Since I'm a Qt beginner, I would appreciate a simple explanation with sufficiently simple code.

      class Statistics(QDialog):
          def __init__(self,filename,right):
              super().__init__(self)
              self.statistics={}
              self.filename=filename
              self.right=right
              
              self.readStatistics()
              if(len(self.statistics.get(self.filename))==10):
                 del self.statistics[self.filename]
              self.statistics.setdefault(self.filename,[]).append(self.right)
              self.charts=self.statistics.get(self.filename)
              self.writeStatistics()
      
              self.set0 = QBarSet("Right Input")
              self.set0.append(self.charts)
              self._bar_series = QBarSeries()
              self._bar_series.append(self.set0) 
              self.chart = QChart()
              self.chart.addSeries(self._bar_series)
              self.chart.setTitle("Learn Progress for Unit: "+filename)
              self.categories = ["Try 1", "Try 2", "Try 3", "Try 4", "Try 5", "Try 6", "Try 7", "Try 8", "Try 9", "Try 10"]
              self._axis_x = QBarCategoryAxis()
              self._axis_x.append(self.categories)
              self.chart.addAxis(self._axis_x, Qt.AlignBottom)
              self._bar_series.attachAxis(self._axis_x)
              self._axis_x.setRange("Try 1", "Try 10")
              self._axis_y = QValueAxis()
              self.chart.addAxis(self._axis_x, Qt.AlignLeft)
              self._bar_series.attachAxis(self._axis_y)
              self._axis_y.setRange(0, 100)
              self.chart.legend().setVisible(True)
              self.chart.legend().setAlignment(Qt.AlignBottom)
              self._chart_view = QChartView(self.chart)
              self._chart_view.setRenderHint(QPainter.RenderHint.Antialiasing)
              **self.setCentralWidget(self._chart_view)**
      
      

      I ask for help!!!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Josef-Michael-Laub
      You should just put a layout (e.g. QHBoxLayout or QVBoxLayout) on the QDialog (via setLayout()) and then add the QChartView onto that (via addWidget()), just like adding any QWidget onto any other QWidget.

      About the only addChild() I know of is in QTreeWidgetItem and that is nothing to do with your situation.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved