QLabel을 상속받은 클래스를 만든후 Q디자이너에서 Prompt to...로 기존의 라벨객체를 PaintLabel 객체로 승격
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class PaintLabel : public QLabel { Q_OBJECT public: PaintLabel(QWidget *parent = nullptr); void mousePressEvent ( QMouseEvent * ev ); void paintEvent ( QPaintEvent * e ); signals: void roiSelect(QVector<QPoint> _points); void roiRelesed(); private: QPoint p; QVector<QPoint> points; }; | cs |
MousePressEvent와 Paint 이벤트 지정
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 | void PaintLabel::mousePressEvent ( QMouseEvent* e ) { p = e->pos(); if(points.size() > 4) points.clear(); if(e -> button() == Qt::LeftButton){ points.push_back(p); if(points.size() > 3){ emit roiSelect(points); points.push_back(points.at(0)); } }else if(e->button() == Qt::RightButton){ points.clear(); emit roiRelesed(); } update(); } void PaintLabel::paintEvent( QPaintEvent * e ){ QPainter painter(this); QPen paintpen(Qt::red); paintpen.setWidth(5); painter.setPen(paintpen); // painter.drawPoint(p); painter.drawPolyline(points); } | cs |
'진행중인 프로젝트 > ImageHandler' 카테고리의 다른 글
[ImageHandler] 참고 자료 (0) | 2019.06.29 |
---|---|
[Qt5] 사용자 정의(. ui)로 다이얼로그 띄운 부분 (0) | 2019.06.29 |
Data Compression With Low-Rank Approximation [ 소스코드 ] (0) | 2019.06.29 |
[ Linear Algebra ] Data Compression With Low-Rank Approximation (0) | 2019.06.28 |
[ Network ] TCP / IP C++ / Python 소켓통신 파트 (0) | 2019.06.28 |