By reimplementing the widget's paintEvent() and using QPainter API to draw.