QScatterSeries中的每个点是否可以具有单独的标记大小? [英] Is it possible to have a individual marker size for each point in a QScatterSeries?

查看:40
本文介绍了QScatterSeries中的每个点是否可以具有单独的标记大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在QPolarChart中绘制一系列点(距离r,角度a,强度s)

I want to plot a series of points (distance r, angle a, strength s) in a QPolarChart

QPolarChart *chart = new QPolarChart();
ScatterSeries *series1 = new QScatterSeries();
series1->setMarkerSize(s);

for(int i = 0; i < count; i++)
{  
    series1->setMarkerSize(s); // ->  of course changes the marker size for the complete series
    series1->append(r, a);
}

chart->addSeries(series1);

现在我要使每个点的标记大小独立,基本上该大小应代表每个点的强度".

Now I want to make the marker size individual for each point, basically the size should represent the "strength" of each point.

我可以为每个点使用自己的QScatterSeries,但我正在寻找更好的实现.

I could use an own QScatterSeries for each point, but I'm looking for a nicer implementation.

推荐答案

没有直接更改标记大小的方法,标记是我们无法设置大小但可以缩放的自定义项目.要获取这些物品,请使用从 QGraphicsView 继承的 QChartView itemAt()方法,如下所示:

There is no direct way to change the size of the marker, markers are custom items that we can not set the size but can scale. To obtain the items, use the itemAt() method of QChartView that inherits from QGraphicsView as shown below:

#include <QApplication>
#include <QtCharts>

QT_CHARTS_USE_NAMESPACE

struct Data{
    qreal r;
    qreal a;
    qreal s;
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QChartView view;
    QPolarChart *chart = new QPolarChart;

    std::vector<Data> data;

    for(int i=0; i <= 360; i+=30){
        data.push_back(Data{i*1.0, i*1.0, 2*qAbs(sin(i*3.14159265358979323846/360))});
    }

    view.setChart(chart);
    QScatterSeries *series = new QScatterSeries;
    for(const Data & d: data){
        *series << QPointF(d.a, d.r);
    }

    chart->addSeries(series);
    chart->createDefaultAxes();
    view.show();

    for(int index= 0; index < series->count(); index++){
        QPointF p =  chart->mapToPosition(series->at(index) , series);
        QGraphicsItem *it = view.itemAt(view.mapFromScene(p));
        it->setTransformOriginPoint(it->boundingRect().center());
        it->setScale(data[index].s);
    }

    return a.exec();
}

这篇关于QScatterSeries中的每个点是否可以具有单独的标记大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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