'Draw the QTextDocument of an item.
Args:
rect: The QRect to clip the drawing to.'

def _draw_textdoc(self, rect):

    clip = QRectF(0, 0, rect.width(), rect.height())
    self._painter.save()
    if (self._opt.state & QStyle.State_Selected):
        option = 'completion.item.selected.fg'
    elif (not (self._opt.state & QStyle.State_Enabled)):
        option = 'completion.category.fg'
    else:
        option = 'completion.fg'
    try:
        self._painter.setPen(config.get('colors', option))
    except configexc.NoOptionError:
        self._painter.setPen(config.get('colors', 'completion.fg'))
    ctx = QAbstractTextDocumentLayout.PaintContext()
    ctx.palette.setColor(QPalette.Text, self._painter.pen().color())
    if clip.isValid():
        self._painter.setClipRect(clip)
        ctx.clip = clip
    self._doc.documentLayout().draw(self._painter, ctx)
    self._painter.restore()
