btns1[i][j]->installEventFilter(this);......bool MainWindow::eventFilter(QObject *object, QEvent *event){ if( event->type() == QEvent::MouseMove){ QPushButton *btn = qobject_cast<QPushButton*>(object); btn->setStyleSheet("background-color: black;"); } if( event->type() == QEvent::MouseButtonPress){ QPushButton *btn = qobject_cast<QPushButton*>(object); btn->setStyleSheet("background-color: white;"); } return QMainWindow::eventFilter(object, event);}
btns1[i][j]->setMouseTracking(true);
QPushButton:pressed { background-color: white; }QPushButton:hover { background-color: black; }