QPainter::save() saves the current state of the painter not the painted device. That state is stored internally to the QPainter and can only live as long as the QPainter exists, which in this case is until the end of the paintEvent(). You never call QPainter::restore() so the saved states are never reused.
Subsequent calls to the paintEvent() only draw the shape associated with the last clicked button because that is the logic you have implemented by clearing the px flag after drawing the shape x.
Bookmarks