CommonButton.hpp 764 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <iostream>
  3. #include <QPushButton>
  4. #include <QWidget>
  5. class CommonButton : public QPushButton{
  6. public:
  7. CommonButton() : QPushButton() {
  8. }
  9. CommonButton(QWidget* qw) : QPushButton(qw) {
  10. this->resize(qw->size());
  11. }
  12. void focusInEvent(QFocusEvent *e) override{
  13. this->setStyleSheet("background-color: rgb(255,255,0);");
  14. }
  15. void focusOutEvent(QFocusEvent *e) override{
  16. this->setStyleSheet("background-color: rgb(255,255,255);");
  17. }
  18. void enterEvent(QEnterEvent *event){
  19. if(this->isEnabled())
  20. this->setStyleSheet("background-color: rgb(255,255,0);");
  21. }
  22. void leaveEvent(QEvent *event){
  23. if(event->type() == QEvent::Leave){
  24. this->setStyleSheet("background-color: rgb(255,255,255);");
  25. }
  26. }
  27. };