How to show a QChartView embedded in a QDialog
-
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!!!
-
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!!!
@Josef-Michael-Laub
You should just put a layout (e.g.QHBoxLayoutorQVBoxLayout) on theQDialog(viasetLayout()) and then add theQChartViewonto that (viaaddWidget()), just like adding anyQWidgetonto any otherQWidget.About the only
addChild()I know of is inQTreeWidgetItemand that is nothing to do with your situation.