2

I'm confused with using QwtPlot class to draw a customized coordinate system. My goal is to draw a coordinate system with customized scale, and draw grid line on these customized scales. Here are the values of the scales:

x-axis and y-axis scale:

x1=-0.642455
x2=0
x3=0.642455
y1=-0.642455
y2=0
y3=0.642455

I read the user's guide of QwtPlot class and QwtPlotGrid class. I found a function in QwtPlotGrid class called setxDiv and seemed that it could help, So I wrote the following code:

QList<double> doubleListmin;//min scale
QList<double> doubleListmed;//medium scale
QList<double> doubleListmaj;//major scale
doubleListmin.append(0.1);
doubleListmed.append(0.3);
doubleListmaj.append(0.642455);
QList<double> doubleList[3];
doubleList[0] = doubleListmin;
doubleList[1] = doubleListmed;
doubleList[2] = doubleListmaj;
QwtScaleDiv *xDiv = new QwtScaleDiv(-0.642455, 0.642455, doubleList);
//lowerbound is -0.642455, upperbound is 0.642455, doubleList customizes the scale

QwtPlotGrid *grid = new QwtPlotGrid();
grid->setXDiv(*xDiv);
//grid->updateScaleDiv(*xDiv, *xDiv);
grid->attach(this);

But it turned out to have no influence on the new QwtPlotGrid, it doesn't change its scale system.

I think there's another way: draw a several lines in the QwtPlot. But I don't know how to do it.

Somebody help me please!!! Thank you in advance~

Mat
  • 202,337
  • 40
  • 393
  • 406
OrionNebular
  • 197
  • 1
  • 2
  • 12

2 Answers2

1

As you said "draw severalk lines" is not good approach because you can't do this lines infinity. To do this there is special class QwtPlotMarker which is more suitable here. Maybe not the best thing in the world, but works as you want:

        QwtPlotMarker *m1=new QwtPlotMarker;
        m1->setLinePen(QPen(Qt::gray));
        m1->setLineStyle(QwtPlotMarker::VLine);
        m1->setValue(0,0);
        m1->attach(ui->qwtPlot);
        QwtPlotMarker *m2=new QwtPlotMarker;
        m2->setLinePen(QPen(Qt::gray));
        m2->setLineStyle(QwtPlotMarker::HLine);
        m2->setValue(0,0);
        m2->attach(ui->qwtPlot);
        QwtPlotMarker *m3=new QwtPlotMarker;
        m3->setLinePen(QPen(Qt::gray));
        m3->setLineStyle(QwtPlotMarker::HLine);
        m3->setValue(0,-0.642455);
        m3->attach(ui->qwtPlot);
        QwtPlotMarker *m4=new QwtPlotMarker;
        m4->setLinePen(QPen(Qt::gray));
        m4->setLineStyle(QwtPlotMarker::HLine);
        m4->setValue(0,0.642455);
        m4->attach(ui->qwtPlot);
        QwtPlotMarker *m5=new QwtPlotMarker;
        m5->setLinePen(QPen(Qt::gray));
        m5->setLineStyle(QwtPlotMarker::VLine);
        m5->setValue(-0.642455,0);
        m5->attach(ui->qwtPlot);
        QwtPlotMarker *m6=new QwtPlotMarker;
        m6->setLinePen(QPen(Qt::gray));
        m6->setLineStyle(QwtPlotMarker::VLine);
        m6->setValue(0.642455,0);
        m6->attach(ui->qwtPlot);

enter image description here

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • Well,thanks!It works!And do you know how to clear these lines in a slot and replot this qwtplot with other lines? – OrionNebular Nov 06 '14 at 03:26
  • @HYSuperman You can set new value `m6->setValue(0.642455*3,0);` or if you want to remove this lines, you can delete markers. For example. ` delete m1; delete m2; delete m4; delete m5; delete m3; delete m6;` – Jablonski Nov 06 '14 at 15:03
  • I know the delete way. But these lines are dynamicly created within a function in my QwtPlot class. I can't delete them outside the function, you see? I can't obtain there name outside the range of the function. So the next time I want to replot the whole QwtPlot, I need to have some functions in QwtPlot class which can clear all the lines on it. @Chernobyl – OrionNebular Nov 08 '14 at 01:36
  • @HYSuperman of course your markers goes out if scope, so you can write markers as a class members, create then in function and delete everywhere in your class. – Jablonski Nov 08 '14 at 04:58
0

Better create your own QwtScaleDiv object setting the ticks manually and assign them using QwtPlot::setAxisScaleDiv(). Update of the grid will happen automatically ( as long as you didn't decouple it explicitly ).

When you also need to manage the tick positions when zooming you have to derive your own scale engine instead - overloading the QwtScaleEngine::divideScale() method.

Uwe
  • 705
  • 3
  • 3