Blame view

LiveChat/FeiTalk/common/ismoothpixmaplabel.cpp 1.73 KB
9f17d59e   陈明泉   no message
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
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include "ismoothpixmaplabel.h"
  #include <QPainter>
  #include <QBitmap>
  #include <QSize>
  #include <QPixmap>
  
  ISmoothPixmapLabel::ISmoothPixmapLabel(QWidget *parent) :
      QLabel(parent)
  {
      isMousein = false;
      setAttribute(Qt::WA_TranslucentBackground);
  }
  void ISmoothPixmapLabel::resizeEvent(QResizeEvent * event )
  {
  //  int side = qMin(width(), height());
  //  //QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side, side, QRegion::Ellipse);
  //  QRegion maskedRegion(this->width()-2, 2, this->width(), this->height(), QRegion::Ellipse);
  //  setMask(maskedRegion);
     QPainterPath path;
     QRectF rect = QRectF(0,0,width(),height());
     path.addRoundRect(rect,10,10);
     QPolygon polygon= path.toFillPolygon().toPolygon();//获得这个路径上的所有的点
     QRegion region(polygon);//根据这个点构造这个区域
     setMask(region);
  }
  
  
  void ISmoothPixmapLabel::enterEvent(QEvent *)
  {
      if(isMousein)
      {
          return;
      }
      isMousein = true;
      emit mouseIn();
  
  }
  
  void ISmoothPixmapLabel::mousePressEvent(QMouseEvent *ev)
  {
      emit mousePress();
  }
  
  void ISmoothPixmapLabel::leaveEvent(QEvent *)
  {
      isMousein = false;
  
      emit mouseOut();
  }
  
  void ISmoothPixmapLabel::paintEvent(QPaintEvent *event)
  {
  
      if (!event) return;
      QLabel::paintEvent(event);
      QPainter painter(this);
  
  //    painter.setRenderHints(QPainter::SmoothPixmapTransform);//消锯齿
  
  //    QBitmap maskImage("E:\project\LiveChat\LiveChat\bin\debug\img\145766289369756.jpg"); //蒙板图片
  
  //    QPixmap iconImage("E:\project\LiveChat\LiveChat\bin\debug\img\145766289369756.jpg");
  
  //    iconImage.setMask(maskImage);
  ////    icon = icon.scaled(QSize(54,54));
  ////    icon.setMask(maskImage);
  
  //    painter.drawPixmap(0, 0, iconImage);
  }