Qt Qwt 只缩放横轴或纵轴(按键控制)

最近有需求,用到了Qwt只缩放单一方向的坐标轴,废话不多说 直接上代码。

由于是绑定按键的,直接放到了按键的槽函数上。

注:以下代码ui->qwtPlot_Temp_GetChange函数,为QwtPlot及曲线显示的子类信息

x轴放大:

void MainFrame::on_pushButton_X_Zoom_In_clicked()
{
    const bool autoReplot = ui->qwtPlot_Temp_GetChange->autoReplot();
    ui->qwtPlot_Temp_GetChange->setAutoReplot( false );


    QwtInterval  xs = ui->qwtPlot_Temp_GetChange->axisScaleDiv(QwtPlot::xBottom ).interval();

    double xs_min = xs.minValue();
    double xs_max = xs.maxValue();
    double xs_differ = (xs_max - xs_min)/2;

    ui->qwtPlot_Temp_GetChange->setAxisScale( QwtPlot::xBottom,	
                      xs_min + xs_differ *0.1,
                      xs_max - xs_differ *0.1);


    ui->qwtPlot_Temp_GetChange->setAutoReplot( autoReplot );
    ui->qwtPlot_Temp_GetChange->replot();
}

x轴缩小:

void MainFrame::on_pushButton_X_Zoom_Out_clicked()
{
    const bool autoReplot = ui->qwtPlot_Temp_GetChange->autoReplot();
    ui->qwtPlot_Temp_GetChange->setAutoReplot( false );

    QwtInterval  xs = ui->qwtPlot_Temp_GetChange->axisScaleDiv(QwtPlot::xBottom ).interval();

    double xs_min = xs.minValue();
    double xs_max = xs.maxValue();
    double xs_differ = (xs_max - xs_min)/2;

    ui->qwtPlot_Temp_GetChange->setAxisScale( QwtPlot::xBottom,	
                      xs_min - xs_differ *0.1,
                      xs_max + xs_differ *0.1);


    ui->qwtPlot_Temp_GetChange->setAutoReplot( autoReplot );
    ui->qwtPlot_Temp_GetChange->replot();
}

y轴放大:

void MainFrame::on_pushButton_Y_Zoom_In_clicked()
{
    const bool autoReplot = ui->qwtPlot_Temp_GetChange->autoReplot();
    ui->qwtPlot_Temp_GetChange->setAutoReplot( false );


    QwtInterval  ys = ui->qwtPlot_Temp_GetChange->axisScaleDiv(QwtPlot::yLeft ).interval();
  
    double ys_min = ys.minValue();
    double ys_max = ys.maxValue();
    double ys_differ = (ys_max - ys_min)/2;

    ui->qwtPlot_Temp_GetChange->setAxisScale( QwtPlot::yLeft,	 
                      ys_min + ys_differ *0.1,
                      ys_max - ys_differ *0.1);


    ui->qwtPlot_Temp_GetChange->setAutoReplot( autoReplot );
    ui->qwtPlot_Temp_GetChange->replot();
}

y轴缩小:

void MainFrame::on_pushButton_Y_Zoom_Out_clicked()
{
    const bool autoReplot = ui->qwtPlot_Temp_GetChange->autoReplot();
    ui->qwtPlot_Temp_GetChange->setAutoReplot( false );


    QwtInterval  ys = ui->qwtPlot_Temp_GetChange->axisScaleDiv(QwtPlot::yLeft ).interval();

    double ys_min = ys.minValue();
    double ys_max = ys.maxValue();
    double ys_differ = (ys_max - ys_min)/2;

    ui->qwtPlot_Temp_GetChange->setAxisScale( QwtPlot::yLeft,	
                      ys_min - ys_differ *0.1,
                      ys_max + ys_differ *0.1);


    ui->qwtPlot_Temp_GetChange->setAutoReplot( autoReplot );
    ui->qwtPlot_Temp_GetChange->replot();
}

代码如上所示,希望对大家有所帮助!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值