Important: Please read the Qt Code of Conduct -

How do I stop repainting on scroll

  • I have created a scrolling area with QGraphicsView and QGraphicsItem, where the Qgraphicsitem is bigger than the view, thus creating a scrolling bar. However when I clicked and moved the scroll bar, the scene kept repainting itself. How do I stop these unnecessary repaints? It's eat up my cpu resource for no reason.

  • Lifetime Qt Champion


    Can you show how you setup your scene/view ?

    By the way:
    What version of Qt are you using ?
    What os are you running ?

  • @SGaist

    I'm using Qt 5.13.2 and Windows 10.
    In my ui file, I created a graphicsView object.


    scene = new QGraphicsScene(this);
    myItem = new CustomerGraphicsItem();
    scene->addItem(myItem )


    void CustomerGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
        QBrush blackBrush(Qt::black);
        painter->fillRect(boundingRect(), blackBrush);
        painter->drawText(blah blah blah)
        qDebug() << "printing...";

    The program redraw every time I move the scroll bar or resize my window.

  • Lifetime Qt Champion

    One thing you can check is the QGraphicsView update mode.

Log in to reply