如何使用Qt Designer在窗体中插入QChartView? [英] How to insert QChartView in form with Qt Designer?
问题描述
我想在表单中添加QChart
.但我无法在小工具箱"中找到它.所以我在代码中创建了它.如何将其插入QWidget
或QFrame
或其他内容?
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:
- 首先在.pro 中添加
- 将QGraphicsView放置到设计中.
- 右键单击QGraphicsView并选择
Promote to...
- 执行上述操作时,将出现一个菜单,该菜单应在
Promoted Class Name
的QChartView
和Header file
的QtCharts
中进行设置,然后按add
按钮,最后按promote
QT += charts
- first add
QT += charts
in the .pro - place the QGraphicsView to the design.
- Right click on the QGraphicsView and select
Promote to...
- When doing the above, a menu appears, in the menu it should be set in
QChartView
inPromoted Class Name
, andQtCharts
inHeader file
, then press theadd
button and finally presspromote
.
某些步骤的屏幕截图:
[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屋!