新建类:
DoubleClickLabel
.h
#pragma once#include <QLabel>class DoubleClickLabel : public QLabel
{Q_OBJECTpublic:DoubleClickLabel(QWidget *parent);~DoubleClickLabel();
signals:void doubleClicked();protected: //这里重写双击事件virtual void mouseDoubleClickEvent(QMouseEvent* event) override;
};
cpp
#include "DoubleClickLabel.h"DoubleClickLabel::DoubleClickLabel(QWidget *parent): QLabel(parent)
{}DoubleClickLabel::~DoubleClickLabel()
{}void DoubleClickLabel::mouseDoubleClickEvent(QMouseEvent* event)
{Q_UNUSED(event);emit doubleClicked();//发射信号
}
拖入Label控件后,右键选择提升为
点击添加
勾选后,点击提升
在mainwindow cpp构造函数中,connect连接信号和槽即可
label_box_img,label_reel_img,为控件label的命名
void mainwindow ::OpenBoxImage()
{
qDebug()<<"执行双击,打开图像";
}
vs QT需要扫描一下项目