qt5
Last change
on this file since c9fa699 was
6bc425e,
checked in by pavelpa <pavelpa@…>, 13 years ago
|
'info' icon scaled to height of tabBar
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[cb18bc7] | 1 | #include "tabwidget.h" |
---|
| 2 | |
---|
| 3 | #include <QMouseEvent> |
---|
| 4 | #include <QPainter> |
---|
[6bc425e] | 5 | #include <QTabBar> |
---|
[cb18bc7] | 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 | { |
---|
[6bc425e] | 16 | int height = tabBar()->tabRect(currentIndex()).height(); |
---|
| 17 | QImage image = mInfoImage.scaled(QSize(height,height),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation); |
---|
[cb18bc7] | 18 | QPainter painter(this); |
---|
[6bc425e] | 19 | painter.drawImage(rect().topRight()-QPoint(image.width(),0),image); |
---|
[cb18bc7] | 20 | } |
---|
| 21 | |
---|
| 22 | void TabWidget::mousePressEvent(QMouseEvent *event) |
---|
| 23 | { |
---|
| 24 | mPressPoint = event->pos(); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void TabWidget::mouseReleaseEvent(QMouseEvent *event) |
---|
| 28 | { |
---|
[6bc425e] | 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())); |
---|
[cb18bc7] | 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.