Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QPen usage with QAreaChart
Forum Updated to NodeBB v4.3 + New Features

Problem with QPen usage with QAreaChart

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 312 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ahmadinho
    wrote on last edited by
    #1

    Hello everybody, I am using QAreaChart in order to create different rectangles, how ever the Pen used when drawing tends to exist until the X-Axis, not around the rectangle, like this image
    4af03930-9dc8-4db0-9c8e-eed087b4c605-image.png

    here's the simple code

    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    #include <QtCharts/QChartView>
    #include <QtCharts/QLineSeries>
    #include <QtCharts/QAreaSeries>
    
    QT_CHARTS_USE_NAMESPACE
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
    //![1]
        QLineSeries *series0 = new QLineSeries();
        QLineSeries *series1 = new QLineSeries();
    //![1]
    
    //![2]
        *series0 << QPointF(1, 10) << QPointF(5, 10) << QPointF(5, 5) << QPointF(1, 5);
    
    //![2]
    
    //![3]
        QAreaSeries *series = new QAreaSeries(series0);
    
        QPen pen(0x059605);
        pen.setWidth(3);
        series->setPen(pen);
    
        QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
        gradient.setColorAt(0.0, 0x3cc63c);
        gradient.setColorAt(1.0, 0x26f626);
        gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
        series->setBrush(gradient);
    //![3]
    
    //![4]
        QChart *chart = new QChart();
        chart->addSeries(series);
        chart->setTitle("Simple areachart example");
        chart->createDefaultAxes();
        chart->axes(Qt::Horizontal).first()->setRange(0, 20);
        chart->axes(Qt::Vertical).first()->setRange(0, 20);
    //![4]
    
    //![5]
        QChartView *chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
    //![5]
    
    //![6]
        QMainWindow window;
        window.setCentralWidget(chartView);
        window.resize(400, 300);
        window.show();
    //![6]
    
        return a.exec();
    }
    
    

    any idea how to fix this? Thanks.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      The docs says
      "To create area charts, we need two QLineSeries instances. They are going to define the upper and lower boundary of the area."

      And you seem to only use one.
      QAreaSeries *series = new QAreaSeries(series0, MISSING!);

      I think you have to define the rectangle as 2 series. like top and bottom.
      I dont have QCharts installed and the installer is acting up so i cant give more details.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Ahmadinho
        wrote on last edited by
        #3

        I split it into two, like this

            *series0 << QPointF(1, 10) << QPointF(5, 10);
                *series1 <<QPointF(5, 5) << QPointF(1, 5);
        //![2]
        
        //![3]
            QAreaSeries *series = new QAreaSeries(series0,series1);
        

        but now the shape is like this
        cd36ceed-245d-43f4-b005-b05b1fc7b116-image.png
        any idea why or how to fix?

        Thanks in advance.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved