Nominate our 2022 Qt Champions!

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->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