QLabel vs QGraphicsView performance
Asked Answered
F

1

12

I am learning QT and I am puzzled by the difference in performance of QLabel and QGraphics view while panning.

I read a huge 36Mpixels (D800) jpeg file into either QLabel or QGraphics objects and try to drag the full scale image with QLabel/Graphics. Surprisingly, the QLabel provides really smooth movement while QGRaphicsView panning is jerky.

The simplified QGraphicsView code is:

QApplication::setGraphicsSystem("raster");    
...
QGraphicsView  view();
view.setDragMode(QGraphicsView::ScrollHandDrag);
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view.setFrameStyle(QFrame::NoFrame);
view.showFullScreen();

QGraphicsPixmapItem *pmItem = new QGraphicsPixmapItem(pixMap);
scene.addItem(pmItem); // only one item in the scene
//view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); // no difference
view.show();

The simplified QLabel based code is:

void MyQLabel::mouseMoveEvent(QMouseEvent *event){
    if(_leftButtonPressed) {
            // calculate new {_x, _y} position
            repaint();
        }
    } else super::mouseMoveEvent(event);
}
void MyQLabel::paintEvent(QPaintEvent *aEvent){
    QPainter paint(this);
    paint.drawPixmap(_x, _y, pixMap);
}

... // Somewhere in the code:
MyQLabel _myLabel(NULL);
_myLabel.showFullScreen();
_myLabel.show();

It feels like QGraphicsView is skipping the over some positions (with fast dragging), while QLabel paints at all intermediate images.

What do I miss?

Thank you Alex

Flooded answered 21/9, 2012 at 0:27 Comment(1)
well , QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene , you, first of all, shouldn't put Items directly inside view.Punishable
P
1

Likely, the QGraphicsView calls update() when a scroll change is detected. While your label calls repaint().

The difference is that update() schedules a call to repaint() and multiple rapid calls to update() may call repaint() a single time.

When fast dragging, you might register multiple mouse events in a short time frame. The QGraphicsView will handle all of them and for each of them call update() and only once they are all processed repaint() is actually called. Your label will force a repaint() for each mouse event.

Your label may be smoother than the graphics view, but it will consume more resources, and on limited hardware the label will lag behind the mouse cursor as the hardware is trying to process all the repaints.

Paigepaik answered 29/8, 2021 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.