Results 1 to 4 of 4

Thread: Very slow repainting ofPixmaps in QGraphicsView images

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Very slow repainting ofPixmaps in QGraphicsView images

    Using the QGraphicsView and QGraphicsScene to render pixmaps generated from a QImage. This is on QT 4.4.3.

    The pixmaps are generated and placed onto the scene from a QGraphicsItemGroup derived class, and manipulated through the returned QGraphicsPixmapItem*.

    The image is a long thin image, that is viewed by scrolling through and I draw graphics path items on.

    This works fine on Windows, but experiences major problems in Linux. Scrolling is very slow. Also drawing onto the view is also very slow. In fact, the whole application slows down hugely. This has made the application unusable.

    The application appears to be spending very little time generating the pixmaps and painting the QGraphicsItemGroup. The time spent drawing the path items is also insignificant.

    It seems that it is redrawing the image itself that is very slow. If I override the GraphicsView:aintEvent function and put a timer in there, this is very slow. (400-800ms)

    It this a known problem in Linux? It works fine in Windows. (The same paintEvent takes around 5-15ms max)

    Has anyone else experienced this? Is there a workaround for Linux?


    Code in : QGraphicsItemGroup - looks like this:

    (note: this takes max 2-3 ms)

    Qt Code:
    1. void BoreholeImage::paint(QPainter* painter,
    2. const QStyleOptionGraphicsItem* option,
    3. QWidget* widget)
    4. {
    5.  
    6. if (m_graphicsItem->type() == QGraphicsPixmapItem::Type) {
    7. // We've already loaded the image to display.
    8. QGraphicsItemGroup::paint(painter, option, widget);
    9.  
    10. // Is there anything to clean up? See below.
    11. if (m_graphicsItemToDelete) {
    12. delete m_graphicsItemToDelete;
    13. m_graphicsItemToDelete = 0;
    14. }
    15.  
    16. return;
    17. }
    18.  
    19.  
    20. m_stream->setSeekPosition(boundingRect().y());
    21. QImage image = m_stream->getImage();
    22. QPixmap pixmap = QPixmap::fromImage(image);
    23. QGraphicsPixmapItem* pixmapItem = scene()->addPixmap(pixmap);
    24. qDebug() << "BoreholeImage" << "pixmap at" << boundingRect().y();
    25. pixmapItem->setPos(0.0, boundingRect().y());
    26. pixmapItem->scale(1.0, boundingRect().height() / pixmap.height());
    27. pixmapItem->setZValue(0.0);
    28.  
    29. removeFromGroup(m_graphicsItem);
    30. scene()->removeItem(m_graphicsItem);
    31.  
    32. // Can't delete the unused rectItem here because this routine's caller
    33. // uses it again after this routine returns. Delete it on the next call.
    34. m_graphicsItemToDelete = m_graphicsItem;
    35.  
    36. m_graphicsItem = pixmapItem;
    37. addToGroup(m_graphicsItem);
    38. QGraphicsItemGroup::paint(painter, option, widget);
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by drexiya; 21st October 2009 at 16:58. Reason: updated contents

Similar Threads

  1. QGraphicsView to fast update images
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 8th May 2009, 22:17
  2. Zooming is too slow with QGraphicsView
    By learning_qt in forum Qt Programming
    Replies: 10
    Last Post: 4th December 2008, 09:23
  3. Slow loading images
    By abbapatris in forum Qt Programming
    Replies: 10
    Last Post: 5th March 2008, 15:52
  4. QGraphicsView user-resizable images - for children
    By magland in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2007, 16:21
  5. Slow painting in QGraphicsView
    By JonathanForQT4 in forum Qt Programming
    Replies: 12
    Last Post: 16th July 2007, 09:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.