Example 2: Drawing a rectangle In this example, we create a new QPushButton widget and use QPainter to draw a colored rectangle on it.python from PyQt4 import QtGui, QtCore class MyButton(QtGui.QPushButton): def paintEvent(self, event): painter = QtGui.QPainter(self) painter.setBrush(QtGui.QColor(255, 0, 0)) painter.drawRect(0, 0, self.width(), self.height()) app = QtGui.QApplication([]) button = MyButton('Click Me') button.show() app.exec_() ``` Both of these examples demonstrate how to use QPainter to paint graphics on a QWidget. These examples are part of the PyQt4.QtGui package library.