qt5
Last change
on this file since 0bb39f5 was
6bc425e,
checked in by pavelpa <pavelpa@…>, 12 years ago
|
'info' icon scaled to height of tabBar
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | #include "tabwidget.h" |
---|
2 | |
---|
3 | #include <QMouseEvent> |
---|
4 | #include <QPainter> |
---|
5 | #include <QTabBar> |
---|
6 | |
---|
7 | TabWidget::TabWidget(QWidget *aParent) |
---|
8 | : QTabWidget(aParent) |
---|
9 | , mPressPoint(0,0) |
---|
10 | { |
---|
11 | mInfoImage = QImage(":/icons/info.png"); |
---|
12 | } |
---|
13 | |
---|
14 | void TabWidget::paintEvent(QPaintEvent *event) |
---|
15 | { |
---|
16 | int height = tabBar()->tabRect(currentIndex()).height(); |
---|
17 | QImage image = mInfoImage.scaled(QSize(height,height),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation); |
---|
18 | QPainter painter(this); |
---|
19 | painter.drawImage(rect().topRight()-QPoint(image.width(),0),image); |
---|
20 | } |
---|
21 | |
---|
22 | void TabWidget::mousePressEvent(QMouseEvent *event) |
---|
23 | { |
---|
24 | mPressPoint = event->pos(); |
---|
25 | } |
---|
26 | |
---|
27 | void TabWidget::mouseReleaseEvent(QMouseEvent *event) |
---|
28 | { |
---|
29 | int height = tabBar()->tabRect(currentIndex()).height(); |
---|
30 | QImage image = mInfoImage.scaled(QSize(height,height),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation); |
---|
31 | QPoint topLeft = rect().topRight()-QPoint(image.width(),0); |
---|
32 | QRect infoRect = QRect(topLeft, topLeft+QPoint(image.width(),image.height())); |
---|
33 | if( (infoRect.contains(event->pos())) && (infoRect.contains(mPressPoint)) ) |
---|
34 | { |
---|
35 | emit(infoIconClicked()); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
Note: See
TracBrowser
for help on using the repository browser.