2013年3月9日星期六

Qwt 筆記 - 圖表上的 Marker 和 Picker


Plot::Plot(QWidget *parent) : QwtPlot(parent)
{
..........
..........

// marker
this->marker = new QwtPlotMarker();
this->marker->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
this->marker->setLabelOrientation(Qt::Vertical);
this->marker->setLineStyle(QwtPlotMarker::VLine);
this->marker->setLinePen(QPen(Qt::yellow, 2, Qt::SolidLine));

this->marker->attach(this);

// picker
this->picker = new QwtPlotPicker(this->canvas());
this->picker->setStateMachine(new QwtPickerPolygonMachine());

this->picker->setRubberBandPen(QColor(Qt::yellow));
this->picker->setRubberBand(QwtPicker::NoRubberBand);

QObject::connect(this->picker, SIGNAL(moved(QPoint)), this, SLOT(picker_moved(QPoint)));

..........
..........
}

void Plot::picker_moved(QPoint pos)
{
..........
..........

        double xTop = this->invTransform(QwtPlot::xBottom,pos.x());
        double yLeft = this->invTransform(QwtPlot::yLeft, pos.y());

        this->marker->setValue(xTop, yLeft);

        // update the screen
        this->replot();
   
        ..........
..........
}

沒有留言: