Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to modify the color and width of a specific grid line in QChartView



  • I want to highlight the only one grid line.

    I tried to subclass QChartView and reimplemented paintEvent(). And then I drew a line in the same place as the gird line.

    But it covers the points on QScatterSeries.

    What i expect is that the points on QScatterSeries covers the new line, or the color and width of a specific grid line can be modified directly.



  • Drawing a QGraphicsRectItem to cover the grid line is the solution.

    QChart * pChart = new QChart(nullptr);
    // add axises, series, points
    QGraphicsRectItem * pItem = new QGraphicsRectItem(0, 0, 0, 0, pChart->graphicsItem());
    pItem->setPen(QPen(Qt::red));
    pItem->setBrush(QPen(Qt::red));
    pItem->setZValue(3); // points on QScatterSeries covers  this item and this item covers grid lines
    pItem->setRect(/*   */); // to cover the gird line
    

Log in to reply