void BasicBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/) { if (_needRepaint == true || _width == 0.0 || _height == 0.0) { _cache = QPixmap(QSize(_width, _height)); QPainter cachedPainter(&_cache); paintBackground(cachedPainter); cachedPainter.setRenderHint(QPainter::TextAntialiasing); paintText(cachedPainter); _needRepaint = false; } painter->drawPixmap(0, 0, _cache); }
void paintEvent(QPaintEvent *) { QSize layoutSize(75, 75); QPainter widgetPainter(this); widgetPainter.fillRect(QRect(QPoint(0, 0), this->size()), Qt::gray); { const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio(); QPixmap cache(layoutSize * devicePixelRatio); cache.setDevicePixelRatio(devicePixelRatio); QPainter cachedPainter(&cache); cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue); cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red); cachedPainter.drawEllipse(QRect(10,10, 55, 55)); QPainter widgetPainter(this); widgetPainter.drawPixmap(QPoint(10, 10), cache); } { const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio(); QImage cache = QImage(layoutSize * devicePixelRatio, QImage::Format_ARGB32_Premultiplied); cache.setDevicePixelRatio(devicePixelRatio); QPainter cachedPainter(&cache); cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue); cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red); cachedPainter.drawEllipse(QRect(10,10, 55, 55)); QPainter widgetPainter(this); widgetPainter.drawImage(QPoint(95, 10), cache); } }
void DisassemblyView::paintEvent(QPaintEvent * evt) { if (_needRepaint == true) { _cache = QPixmap(viewport()->size()); QPainter cachedPainter(&_cache); paintBackground(cachedPainter); paintSelection(cachedPainter); cachedPainter.setRenderHint(QPainter::TextAntialiasing); cachedPainter.setFont(font()); paintText(cachedPainter); _needRepaint = false; } QPainter p(viewport()); p.drawPixmap(0, 0, _cache); paintCursor(p); }