如何使用Qt Designer在窗体中插入QChartView? [英] How to insert QChartView in form with Qt Designer?

查看:3687
本文介绍了如何使用Qt Designer在窗体中插入QChartView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表单中添加QChart.但我无法在小工具箱"中找到它.所以我在代码中创建了它.如何将其插入QWidgetQFrame或其他内容?

I want to add QChart to the form. But I can't find it in the Widget Box. So I created it in the code. How can I insert it in QWidget or QFrame or something else?

我想在QtDesigner中设置该小部件的区域.

I want to set area of that widget in QtDesigner.

推荐答案

选项1:升级

我想您的意思是插入QChartView,因为QChartView继承自QGraphicsView,所以这是一个不错的选择,为此,我们执行以下操作:

Option 1: Promoted

I suppose you mean inserting a QChartView, because QChartView inherits from QGraphicsView, this would be a good option, for this we do the following:

  1. 首先在.pro
  2. 中添加QT += charts
  3. 将QGraphicsView放置到设计中.
  4. 右键单击QGraphicsView并选择Promote to...
  5. 执行上述操作时,将出现一个菜单,该菜单应在Promoted Class NameQChartViewHeader fileQtCharts中进行设置,然后按add按钮,最后按promote
  1. first add QT += charts in the .pro
  2. place the QGraphicsView to the design.
  3. Right click on the QGraphicsView and select Promote to...
  4. When doing the above, a menu appears, in the menu it should be set in QChartView in Promoted Class Name, and QtCharts in Header file, then press the add button and finally press promote.

某些步骤的屏幕截图:

[3.]

[4.1]

[4.2]

使用QWidget作为基础而不是QGraphicsView,可以完成相同的操作.

The same could be done using QWidget as a base instead of QGraphicsView.

为什么选择一个或另一个小部件作为基础?

之所以选择它,是因为Qt Designer通过moc在默认情况下会建立某些属性,并且如果窗口小部件不具有该方法,则它将无法编译.由于所有小部件都从QWidget继承而来,因此这将成为任何新的小部件在Qt Designer中对其进行推广的基础.

It is chosen because Qt Designer through moc establishes certain properties by default, and if the widget does not have that method then it will not compile. as all widgets inherit from QWidget this would be the basis for any new widget to promote it in Qt Designer.

在下面的链接中,您将找到一个示例.

In the following link you will find an example.

另一种选择是为QtDesigner编译QtChart插件,因为它必须从以下

Another option would be to compile the QtChart plugin for QtDesigner, for it you must download the 5 files from the following link:

然后执行以下操作:

qmake
make
sudo make install

最后,您可以在Qt Designer中访问QtCharts::QChartView

At the end you can access QtCharts::QChartView in Qt Designer

这篇关于如何使用Qt Designer在窗体中插入QChartView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆