| 1 | #include "InteractiveLabel.h" |
| 2 | #include <QApplication> |
| 3 | #include <QPalette> |
| 4 | |
| 5 | InteractiveLabel::InteractiveLabel(QWidget *parent) |
| 6 | : QLabel(parent) |
| 7 | { |
| 8 | setEnabled(true); |
| 9 | setAutoFillBackground(true); |
| 10 | } |
| 11 | |
| 12 | void InteractiveLabel::highlight(bool state) |
| 13 | { |
| 14 | // I first tried with style sheets, but then I found in the |
| 15 | // documentation that Qt style sheets are currently not supported for |
| 16 | // QMacStyle (the default style on Mac OS X). |
| 17 | // So I use a QPalette for now. |
| 18 | if (state) { |
| 19 | QPalette fiddle = QApplication::palette(); |
| 20 | fiddle.setColor(QPalette::Active, QPalette::Window, Qt::yellow); |
| 21 | setPalette(fiddle); |
| 22 | } else { |
| 23 | setPalette(QApplication::palette()); |
| 24 | } |
| 25 | update(); |
| 26 | } |
| 27 | |
| 28 | void InteractiveLabel::enterEvent(QEvent* /*event*/) |
| 29 | { |
| 30 | emit mouseOver(true); |
| 31 | } |
| 32 | |
| 33 | void InteractiveLabel::leaveEvent(QEvent* /*event*/) |
| 34 | { |
| 35 | emit mouseOver(false); |
| 36 | } |