Question

I'm not terribly familiar with Qt's memory model especially when it comes to image handling. I'm created a blank pixmap and adding it to a QGraphicsView's scene. This seems to work correctly jumping between two sizes, but I've noticed I get graphical artifacts calling this function if I open a QFileDialog (before and after). These artifacts are in the actual view as I can pan around and they stay present. It doesn't seem to matter where on screen the QFileDialog pops up, I still get these issues.

Is there something I need to do to manually rerender that portion of the image or do I probably have more serious problems elsewhere in the code?

void RenderView::setViewport(int width, int height)
{
    if (_viewportOverlay != 0)
        scene()->removeItem(_viewportOverlay);

    const int BORDER = VIEWPORT_BORDER;
    QImage image(width+BORDER*2,height+BORDER*2, QImage::Format_ARGB32);
    QPixmap pixmap = QPixmap::fromImage(image);

    _viewportOverlay = scene()->addPixmap(pixmap);
}
Was it helpful?

Solution

Documentation for that QImage constructor says

Warning: This will create a QImage with uninitialized data. Call fill() to fill the image with an appropriate pixel value before drawing onto it with QPainter.

so I'd suggest adding an image.fill(0) before doing anything with the pixmap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top