-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLabel.cpp
More file actions
58 lines (50 loc) · 1.19 KB
/
Copy pathMyLabel.cpp
File metadata and controls
58 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "MyLabel.h"
#include <QDebug>
#include<QLabel>
#include<QMouseEvent>
int labelHeight;
int labelWidth;
int sizeChangeCount=0;//记录窗口大小改变次数
MyLabel::MyLabel(QWidget *parent) :
QLabel(parent)
{
time=new QTimer(this);
connect(time,SIGNAL(timeout()),this,SLOT(updateSize()));
this->setWindowTitle(QString::fromLocal8Bit("图像"));
}
void MyLabel::mousePressEvent(QMouseEvent *ev)//获取略缩图的鼠标位置
{
int x0=ev->x();
int y0=ev->y();
if(ev->button()==Qt::LeftButton)
{
//触发鼠标按下信号记录鼠标选择的点的坐标
emit sendlocation(x0,y0);
}
//鼠标右键点击事件
if(ev->button()==Qt::RightButton)
{
emit currentOver();
//右键启动输出选择的区域
}
}
void MyLabel::updateSize()
{
qDebug()<<labelHeight;
qDebug()<<labelWidth;
emit sendLabelSize(labelHeight,labelWidth);
if(time->isActive())
{
time->stop();
}
}
void MyLabel::resizeEvent(QResizeEvent *event)
{
if(sizeChangeCount!=0)
{
time->start(1000);
}
sizeChangeCount++;
labelHeight=event->size().height();
labelWidth=event->size().width();
}