Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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

    Hi,

    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.

    mainwindow.cpp

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

    mycustomeitem.cpp

    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