使用表中坐标的QVector填充QScatterDataArray

时间:2018-05-23 11:46:55

标签: c++ qt

我想用QScatterDataArray填充一些QVector3D,它们自己从数组中获取数据。我知道如何手动完成,但我不知道如何自动完成。我想你将不得不使用for循环,但我不知道如何。我还想说我从不使用QT,所以答案对你来说似乎很明显。

以下是我要修改的代码:

// "graph" is therefore my graph

QScatter3DSeries *series = new QScatter3DSeries(graph);
QScatterDataArray data;

data << QVector3D(50, 10, 0) << QVector3D(5, 8, 9) << QVector3D(0, 10, 15)
<< QVector3D(30, 50, 02) << QVector3D(15, 83, 7) << QVector3D(04, 20, 45)
<< QVector3D(40, 014, 10) << QVector3D(35, 28, 21) << QVector3D(04, 0, 15)
<< QVector3D(70, 10, 27) << QVector3D(15, 28, 47) << QVector3D(062, 70, 45)
<< QVector3D(50, 10, 0) << QVector3D(5, 8, 17) << QVector3D(031, 20, 35);

series->dataProxy()->addItems(data);
graph->addSeries(series);

谢谢:)

1 个答案:

答案 0 :(得分:2)

对于QScatterDataArray的向量,QScatterDataItemstypedef

QScatterDataItemconstructorQVector3D

因此,迭代坐标表,为每个坐标构建QVector3Dpush_back构建data

这样做的唯一方法是:

QScatterDataArray data;

for ( /* each xyz coordinate in some table */ )
{
    data.push_back(QScatterDataItem(QVector3d(x, y, z)));
}