qgis-sample-QgsRubberBand.py
from PyQt4.QtGui import QColor
from qgis.core import QgsGeometry, QgsPoint
from qgis.gui import QgsRubberBand
from qgis.utils import iface
canvas = iface.mapCanvas()
r_polyline = QgsRubberBand(canvas, False)
points = [QgsPoint(-1, -1), QgsPoint(0, 1), QgsPoint(1, -1)]
r_polyline.setToGeometry(QgsGeometry.fromPolyline(points), None)
r_polyline.setWidth(2)
r_polygone = QgsRubberBand(canvas, True)
points = [[QgsPoint(3, 5), QgsPoint(5, 9), QgsPoint(8, 5)]]
r_polygone.setToGeometry(QgsGeometry.fromPolygon(points), None)
r_polygone.setColor(QColor(0, 0, 255))
r_polygone.setWidth(3)