是否可以为 QScatterSeries 中的每个点设置单独的标记颜色?
Is it possible to have an individual marker color for each point in a QScatterSeries?
表明可以为 QScatterSeries 中的每个点设置单独的标记大小。每个点的单独标记颜色怎么样?
圆圈是QGraphicsEllipseItem所以你可以投射它们,然后使用setBrush方法设置颜色:
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);
<b>if(QGraphicsEllipseItem *ellipse = qgraphicsitem_cast(it)){
QColor color = QColor::fromRgb(QRandomGenerator::global()->generate());;
ellipse->setBrush(color);
}</b>
}
圆圈是QGraphicsEllipseItem所以你可以投射它们,然后使用setBrush方法设置颜色:
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);
<b>if(QGraphicsEllipseItem *ellipse = qgraphicsitem_cast(it)){
QColor color = QColor::fromRgb(QRandomGenerator::global()->generate());;
ellipse->setBrush(color);
}</b>
}