Ai
29 Star 300 Fork 173

ALONE_WORK/QtModuleTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
001-zoomPartWave.cpp 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
ALONE_WORK 提交于 2020-07-27 21:34 +08:00 . 添加波形缩放代码片段。
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();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/ALONE_WORK/QtCeShiXiangMu.git
git@gitee.com:ALONE_WORK/QtCeShiXiangMu.git
ALONE_WORK
QtCeShiXiangMu
QtModuleTest
master

搜索帮助