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

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

问题描述

我想将 QChart 添加到表单中.但是我在小部件框中找不到它.所以我在代码中创建了它.如何将它插入 QWidgetQFrame 或其他东西?

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

解决方案

选项 1:升级

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

  1. 首先在.pro中添加QT += charts
  2. 将 QGraphicsView 放置到设计中.
  3. 右键单击 QGraphicsView 并选择 Promote to...
  4. 执行上述操作时,会出现一个菜单,在菜单中应该在Promoted Class Name中的QChartViewQtCharts中设置头文件,然后按add按钮,最后按promote.

部分步骤截图:

[3.]

[4.1]

[4.2]

同样可以使用 QWidget 作为基础而不是 QGraphicsView.

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

选择它是因为Qt Designer通过moc默认建立了某些属性,如果widget没有那个方法就不会编译.由于所有小部件都继承自 QWidget,这将成为任何新小部件在 Qt 设计器中推广它的基础.

在下面的

然后执行以下操作:

qmake制作须藤制作安装

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

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?

I want to set area of that widget in QtDesigner.

解决方案

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

Screenshots of some steps:

[3.]

[4.1]

[4.2]

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

Why is one or another widget chosen as a base?

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.


Option 2: QtChart plugin

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

Then you execute the following:

qmake
make
sudo make install

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

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

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