InteractiveLabel.cpp 833 B

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