'Copy the image from the Agg canvas to the qt.drawable.
In Qt, all drawing should be done inside of here when a widget is
shown onscreen.'

def paintEvent(self, e):

    if (not hasattr(self, u'renderer')):
        return
    if ((self._dpi_ratio_prev is None) or (self._dpi_ratio != self._dpi_ratio_prev)):
        self._update_figure_dpi()
        event = QtGui.QResizeEvent(self.size(), self.size())
        self.resizeEvent(event)
        self._dpi_ratio_prev = self._dpi_ratio
    painter = QtGui.QPainter(self)
    if self._bbox_queue:
        bbox_queue = self._bbox_queue
    else:
        painter.eraseRect(self.rect())
        bbox_queue = [Bbox([[0, 0], [self.renderer.width, self.renderer.height]])]
    self._bbox_queue = []
    for bbox in bbox_queue:
        (l, b, r, t) = map(int, bbox.extents)
        w = (r - l)
        h = (t - b)
        reg = self.copy_from_bbox(bbox)
        buf = reg.to_string_argb()
        qimage = QtGui.QImage(buf, w, h, QtGui.QImage.Format_ARGB32)
        if hasattr(qimage, u'setDevicePixelRatio'):
            qimage.setDevicePixelRatio(self._dpi_ratio)
        origin = QtCore.QPoint(l, (self.renderer.height - t))
        painter.drawImage((origin / self._dpi_ratio), qimage)
        if ((QT_API == u'PySide') and six.PY3):
            ctypes.c_long.from_address(id(buf)).value = 1
    if (self._drawRect is not None):
        pen = QtGui.QPen(QtCore.Qt.black, (1 / self._dpi_ratio), QtCore.Qt.DotLine)
        painter.setPen(pen)
        (x, y, w, h) = self._drawRect
        painter.drawRect(x, y, w, h)
    painter.end()
