[英]Qt 5.10 - How to add a chart example to a layout
It's my very first experience with Qt so i hope its a basic question with a basic answer I couldn't find. 这是我第一次接触Qt,所以我希望它是一个基本问题,但找不到基本答案。 I need to add a "custom" chart widget
我需要添加一个“自定义”图表小部件
(like in the following example: https://doc.qt.io/qt-5.10/qtcharts-zoomlinechart-example.html )
(如以下示例中所示: https : //doc.qt.io/qt-5.10/qtcharts-zoomlinechart-example.html )
to some Qt container like "layout" or "form" . 到一些Qt容器,例如“ layout”或“ form” 。 Its very straightforward when you have the widget in the toolbox and you use the designer but since it is a custom widget i cannot do that.
当您将小部件放在工具箱中并使用设计器时,它非常简单,但是由于它是自定义小部件,因此我无法做到这一点。
How do you do this in Qt creator? 您如何在Qt Creator中做到这一点?
If your Chart class inherits from QWidget, you have two ways to do this: 如果您的Chart类是从QWidget继承的,则有两种方法可以做到这一点:
In the Design mode, put a QWidget on your Window, or into a Layout. 在设计方式下,将QWidget放在窗口或布局中。 Then, right click on it and select "Promote to ...".
然后,右键单击它并选择“ Promote to ...”。 There, write your class name in "Promoted class name".
在此,在“升级的班级名称”中输入班级名称。
In your window cpp file, write: 在您的窗口cpp文件中,输入:
YourChartClass* ycc = new YourChartClass(this); ycc.show();
or 要么
YourChartClass* ycc = new YourChartClass(); this->layout()->addWidget(ycc)
If your chart inherits from another class, and that class inherits from QWidget, the code lines are the same. 如果您的图表从另一个类继承,并且该类从QWidget继承,则代码行是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.