QWT类的一些使用方法

<pre name="code" class="cpp">鼠标滚轮放大缩小:

    QwtPlotMagnifier *PM = new QwtPlotMagnifier( ui->qwtPlot->canvas() );

鼠标左键拖动波形:

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



                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值