代码拉取完成,页面将自动刷新
1. 首先需要实现鼠标的点击、移动、释放事件
2. 再到事件里面实现,实现时使用的QRubberBand类
#include <QRubberBand>
xxx.h中
private:
QRubberBand *RubBand;
xxx.cpp中
SignalWave::SignalWave(const int &Ch, QWidget *parent) :
QWidget(parent),
ui(new Ui::SignalWave),
RubBand(new QRubberBand(QRubberBand::Rectangle, this)), // 使用初始化列表初始化RubBand变量
ChNumber(Ch)
{
ui->setupUi(this);
}
void SignalWave::mousePressEvent(QMouseEvent *e)
{
if(!ui->SglWave->viewport().contains(e->pos())) return;
if(e->button() == Qt::LeftButton) {
if(!RubBand->isVisible()) {
StartPoint = e->pos();
StartPoint.setY(0);
RubBand->setGeometry(QRect(StartPoint, QSize()));
RubBand->show();
}
}
else if(e->button() == Qt::MidButton) {
ui->SglWave->rescaleAxes();
ui->SglWave->replot();
}
}
void SignalWave::mouseMoveEvent(QMouseEvent *e)
{
if(!ui->SglWave->viewport().contains(e->pos())) return;
if(RubBand->isVisible()) {
QPoint EndPoint = e->pos();
EndPoint.setY(ui->SglWave->height());
RubBand->setGeometry(QRect(StartPoint, EndPoint).normalized());
}
}
void SignalWave::mouseReleaseEvent(QMouseEvent *e)
{
if(!ui->SglWave->viewport().contains(e->pos())) return;
if(e->button() == Qt::LeftButton) {
const QRect zoomRect = RubBand->geometry();
int xp1, yp1, xp2, yp2;
zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
double x1 = ui->SglWave->xAxis->pixelToCoord(xp1);
double x2 = ui->SglWave->xAxis->pixelToCoord(xp2);
ui->SglWave->xAxis->setRange(x1, x2);
RubBand->hide();
ui->SglWave->replot();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。