简体   繁体   English

Qt 5.10-如何将图表示例添加到布局

[英]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继承的,则有两种方法可以做到这一点:

  1. 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". 在此,在“升级的班级名称”中输入班级名称。

  2. 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.

相关问题 如何在Qt中添加项目到布局? - How can I add items to a layout in Qt? 如何在Qt中将滚动条添加到网格布局? - How to add a Scroll Bar to a Grid Layout in Qt? 如何将 object 添加到 qt 中的现有布局中? - 解决了 - How to add an object into an existing layout in qt? --Solved 在新的qt 5.10上javaScriptWindowObjectCleared()的替代方法是什么?在qt 5.10上无法识别javaScriptWindowObjectCleared - what is the alternative of javaScriptWindowObjectCleared() on new qt 5.10 ?javaScriptWindowObjectCleared is not recognized on qt 5.10 使用Python(PyQT 5.10)在QT 5.10中加载自己的字体 - Load own font in QT 5.10 with Python (PyQT 5.10) 如何将动态小部件添加到 QT 中的小部件布局中 - How can i add dynamically widget into a widget's layout in QT 如何动态地将小部件(例如QPushButton)添加到设计器内置的布局中 - How to add a widget (QPushButton for example) dynamically to a layout built in designer 如何添加到Qt书籍示例中,例如将项目添加到列表中? - How to add to Qt books example something like add item to list possibility? QT 5.10文档中有关Qt Quick中键盘焦点的错误? - A bug about Keyboard Focus in Qt Quick in QT 5.10 document? 为什么Qt图表示例不会删除动态分配的变量 - Why Qt chart example does not delete dynamically allocated variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM