import sysfrom PyQt6 import QtWidgets, QtGui, QtCoreclass PainterButton(QtWidgets.QWidget): def __init__(self): super().__init__() def paintEvent(self, event): painter = QtGui.QPainter(self) painter.setPen(QtGui.QPen(QtCore.Qt.GlobalColor.blue, 5)) painter.setBrush(QtGui.QBrush(QtCore.Qt.GlobalColor.gray)) painter.drawRect(20,20,300,300)if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) w = PainterButton() w.show() sys.exit(app.exec())
I'm new in pyqt. How can use a drawed shape using pyqt qpainter as a button, so i want when mouse cursor is on it, its color to be changed. how can i do it?
How can change qpainter color when mouse is over it? thanks for any suggesions