QT缓存QGraphicsView的背景图问题

//设置缓存背景模式
setCacheMode(CacheBackground);缓存

//设置背景位图
void RtPrintView::setBackgroundImage(const QImage &img)
{
    m_background = img;
    resetCachedContent();    //注意,使用该函数才能刷新背景层
}函数

//绘制背景位图
void RtPrintView::drawBackground(QPainter *painter, const QRectF &rect)
{
    if (!m_background.isNull())
        painter->drawImage(sceneRect().toRect(), m_background);
    QGraphicsView::drawBackground(painter, rect);
}im

//关键在这个函数:
resetCachedContent();img

相关文章
相关标签/搜索