- QwtPlotPanner *PQ= new QwtPlotPanner( ui->qwtPlot->canvas() );
鼠标左键选择区域放大:(右键还原)
- QwtPlotZoomer* zoomer = new QwtPlotZoomer( ui->qwtPlot->canvas() );
- zoomer->setRubberBandPen( QColor( Qt::black ) );
- zoomer->setTrackerPen( QColor( Qt::black ) );
- zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlModifier );
- zoomer->setMousePattern(QwtEventPattern::MouseSelect3,Qt::RightButton );
设置X轴下面标识:
- ui->qwtPlot->setAxisTitle(QwtPlot::xBottom, "x -->" );
设置X轴取值范围:
- ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0.0, 30.0);
设置Y轴左边标识(竖着显示):
- ui->qwtPlot->setAxisTitle(QwtPlot::yLeft, "y -->");
设置Y轴取值范围:
- ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
创建一个sin()曲线:
- QwtPlotCurve *cSin = new QwtPlotCurve("y = sin(x)");
- cSin->setRenderHint(QwtPlotItem::RenderAntialiased);
- cSin->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
- cSin->setPen(QPen(Qt::blue));
- cSin->attach(ui->qwtPlot);
- cSin->setData(new FunctionData(::sin));
其中FunctionData为:
class FunctionData: public QwtSyntheticPointData{public:FunctionData(double(*y)(double)):QwtSyntheticPointData(100),d_y(y){}virtual double y(double x) const{return d_y(x);}private:double(*d_y)(double);};
- class FunctionData: public QwtSyntheticPointData
- {
- public:
- FunctionData(double(*y)(double)):
- QwtSyntheticPointData(100),
- d_y(y)
- {
- }
- virtual double y(double x) const
- {
- return d_y(x);
- }
- private:
- double(*d_y)(double);
- };
| 创建波形标识:(Y=0)QwtPlotMarker *mY = new QwtPlotMarker();mY->setLabel(QString::fromLatin1("y = 0"));mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);mY->setLineStyle(QwtPlotMarker::HLine);mY->setYValue(0.0);mY->attach(ui->qwtPlot);
- QwtPlotMarker *mY = new QwtPlotMarker();
- mY->setLabel(QString::fromLatin1("y = 0"));
- mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
- mY->setLineStyle(QwtPlotMarker::HLine);
- mY->setYValue(0.0);
- mY->attach(ui->qwtPlot);
创建波形标识:(X=PI/2)QwtPlotMarker *mX = new QwtPlotMarker();mX->setLabel(QString::fromLatin1("x = PI/2"));mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);mX->setLabelOrientation(Qt::Vertical);mX->setLineStyle(QwtPlotMarker::VLine);mX->setLinePen(QPen(Qt::black, 1, Qt::DashDotDotLine));mX->setXValue(M_PI/2);mX->attach(ui->qwtPlot);
- QwtPlotMarker *mX = new QwtPlotMarker();
- mX->setLabel(QString::fromLatin1("x = PI/2"));
- mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
- mX->setLabelOrientation(Qt::Vertical);
- mX->setLineStyle(QwtPlotMarker::VLine);
- mX->setLinePen(QPen(Qt::black, 1, Qt::DashDotDotLine));
- mX->setXValue(M_PI/2);
- mX->attach(ui->qwtPlot);
设置qwtPlot的画布:(圆角矩形)ui->qwtPlot->canvas()->setLineWidth( 1 );ui->qwtPlot->canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );ui->qwtPlot->canvas()->setBorderRadius( 15 );
- ui->qwtPlot->canvas()->setLineWidth( 1 );
- ui->qwtPlot->canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
- ui->qwtPlot->canvas()->setBorderRadius( 15 );
设置qwtPlot的画布:(白色填充)QPalette canvasPalette( Qt::white );canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );ui->qwtPlot->canvas()->setPalette( canvasPalette );
- QPalette canvasPalette( Qt::white );
- canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
- ui->qwtPlot->canvas()->setPalette( canvasPalette );
设置整个界面的颜色:QPalette pal = palette();const QColor buttonColor = pal.color( QPalette::Button );QLinearGradient gradient( 0, 0, 0, 1 );gradient.setCoordinateMode( QGradient::StretchToDeviceMode );gradient.setColorAt( 0.0, Qt::white );gradient.setColorAt( 0.7, buttonColor );gradient.setColorAt( 1.0, buttonColor );pal.setBrush( QPalette::Window, gradient );setPalette( pal );
- QPalette pal = palette();
- const QColor buttonColor = pal.color( QPalette::Button );
- QLinearGradient gradient( 0, 0, 0, 1 );
- gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
- gradient.setColorAt( 0.0, Qt::white );
- gradient.setColorAt( 0.7, buttonColor );
- gradient.setColorAt( 1.0, buttonColor );
- pal.setBrush( QPalette::Window, gradient );
- setPalette( pal );
| |