qt5
Line | |
---|
1 | #include "tabwidget.h" |
---|
2 | |
---|
3 | #include <QMouseEvent> |
---|
4 | #include <QPainter> |
---|
5 | |
---|
6 | #include <QDebug> |
---|
7 | |
---|
8 | const int SPACER = 5; |
---|
9 | |
---|
10 | TabWidget::TabWidget(QWidget *aParent) |
---|
11 | : QTabWidget(aParent) |
---|
12 | , mPressPoint(0,0) |
---|
13 | { |
---|
14 | mInfoImage = QImage(":/icons/info.png"); |
---|
15 | } |
---|
16 | |
---|
17 | void TabWidget::paintEvent(QPaintEvent *event) |
---|
18 | { |
---|
19 | QPainter painter(this); |
---|
20 | painter.drawImage(rect().topRight()-QPoint(mInfoImage.width()+SPACER,-SPACER),mInfoImage); |
---|
21 | } |
---|
22 | |
---|
23 | void TabWidget::mousePressEvent(QMouseEvent *event) |
---|
24 | { |
---|
25 | mPressPoint = event->pos(); |
---|
26 | } |
---|
27 | |
---|
28 | void TabWidget::mouseReleaseEvent(QMouseEvent *event) |
---|
29 | { |
---|
30 | QPoint topLeft = rect().topRight()-QPoint(mInfoImage.width()+SPACER,-SPACER); |
---|
31 | QRect infoRect = QRect(topLeft, topLeft+QPoint(mInfoImage.width(),mInfoImage.height())); |
---|
32 | if( (infoRect.contains(event->pos())) && (infoRect.contains(mPressPoint)) ) |
---|
33 | { |
---|
34 | emit(infoIconClicked()); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
Note: See
TracBrowser
for help on using the repository browser.