Results 1 to 12 of 12

Thread: Slow Movement of QGraphicsItem

  1. #1
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Slow Movement of QGraphicsItem

    Hi All,

    I have one big performance problem in my App which i am not able to figure out.I have one Image which is basically QGraphicsPixmapItem and that iam resizing it to make it appear on my small screen meant to display images.Its resolution is SXGA(1280*1024) and When iam drawing some QGraphicsItem lets say an Rectangle and try to drag it its movement is very slow.

    I have tried all the flags settings.But thats not helping me out.Is there some rendering tips which i need to keep in mind while drawing a QGraphicsItem.

    Please help me out.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slow Movement of QGraphicsItem

    Without seeing a small example that shows us exactly what you are doing, and how the image and the rectangle are related to each other, we can only guess.

  3. #3
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow Movement of QGraphicsItem

    Quote Originally Posted by ChrisW67 View Post
    Without seeing a small example that shows us exactly what you are doing, and how the image and the rectangle are related to each other, we can only guess.

    Qt Code:
    1. //This CImageWidgetOverlay is derived from QGraphicsItem
    2. void CImageWidgetOverlay::paint(QPainter * p, const QStyleOptionGraphicsItem * option, QWidget * widget)
    3. {
    4. if (this->isActive() && m_ShowOverlay)
    5. {
    6. if(m_ROIsList && !m_ROIsList->isEmpty())
    7. {
    8. for(int i = 0; i < m_ROIsList->count(); i++)
    9. {
    10. if (m_DisplayOverlayMask && (!m_OverlayMaskImage.isNull()) && (m_ROIsList->at(i)->getShape() == FA5_SHAPE_RECT_MASK))
    11. {
    12.  
    13. double fScale = m_ROIsList->at(i)->getCurrentScale();
    14. QRectF rect = QRectF(m_OverlayOffsetCol * fScale, m_OverlayOffsetRow * fScale, m_OverlayMaskImage.width() * fScale,
    15. m_OverlayMaskImage.height() * fScale);
    16. p->drawImage(rect , m_OverlayMaskImage, m_OverlayMaskImage.rect());
    17.  
    18.  
    19. }
    20. m_ROIsList->at(i)->drawROI(p);
    21. }
    22. QRectF roiBoundary = m_ROIsList->at(0)->mappedRect();
    23. m_ResultBar->move(roiBoundary.right() + 10, roiBoundary.bottom() - m_ResultBar->rect().height());
    24. m_ResultBar->drawResultBar(p);
    25. }
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CGraphicsScene::initImage(QImage* image)
    2. {
    3. m_CurrentImage = image;
    4. if(m_CurrentImage)
    5. {
    6. m_Resolution = CResolution::getResolutionID(m_CurrentImage->size());
    7. }
    8. setDefaultImage(m_CurrentImage);
    9. update(this->sceneRect());
    10. }
    11.  
    12. void CGraphicsScene::setDefaultImage(QImage* image)
    13. {
    14. m_widgetPixmap->setPixmap(QPixmap::fromImage(*image));
    15. setSceneRect(image->rect());
    16. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slow Movement of QGraphicsItem

    You are resizing a number of images every time you go through the paintEvent(), which happens a lot when dragging even though the image is not changing size. You should consider rendering the images into a QPixmap only when they are resized (or changed) and use a QPixmapCache.

  5. #5
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow Movement of QGraphicsItem

    Thanks Chris for ur reply .Can you be more specific by second line ...??

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slow Movement of QGraphicsItem

    Can you be more specific by second line ...??
    Look at the QGraphicsItem::setCacheMode() flags. Use QGraphicsItem::DeviceCoordinateCache. If you set this flag in the constructor of your class, then the paint() method will be called only when the items changes size. Otherwise, it will always be redrawn using the behind-the-scenes pixmap cache.

    (Don't know what's up with the "QTCLASS" tags today - they are now all showing up as links to the Digia.com site, and all of them are giving me a 404 error, even this link to QWidget).
    Last edited by d_stranz; 19th September 2012 at 16:35.

  7. #7
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow Movement of QGraphicsItem

    d_stranz i Have tried this flag also but the result is same.No change....Okie i will try to elaborate my problem..

    We are actually using one image which continuously comes from a camera
    onto a QGraphicsPixmapItem.This QGraphicsPixmapItem i am adding to
    QGraphicsScene.Then we are resizing this image widget into which we are
    displaying this camera image with aspect ratio 4:3.The Resolution of the
    image is SXGA.
    Then we are drawing different shapes (Region of interest) on top of this
    image. If we try to drag these shapes the dragging is not smooth.We have
    other resolutions like VGA, QVGA etc.Dragging is somewhat smooth on
    these smaller resolutions.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slow Movement of QGraphicsItem

    So you mean you are trying to move a rectangle (ROI) that is a child of the QGraphicsPixmapItem that contains the image that is simultaneously being downloaded from a camera, resized to fit the pixel dimensions of the view, and then updated on screen?

    Any user interaction with the ROI is going to be very slow with respect to the refresh rate of the camera image, and every movement of the ROI is going to cause an update on the image, so it sounds to me like you are getting double updates every time the ROI is moved.

    I would try separating your GUI into two different widgets: the graphics view that contains the image, and an overlay widget (with a transparent background) that contains another graphics view of the same dimensions and sits exactly on top of the image view. You use this view to display and interact with the ROI items.

    You could also try freezing updates (or greatly reducing the frequency) of the image when an ROI move is in progress.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Slow Movement of QGraphicsItem

    I would even say that every move is going to cause a rescale and an update as I'm assuming it is the item that is being scaled and not the image prior to attaching it to the item. Since the image is constantly changing, caching indeed will not help much.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow Movement of QGraphicsItem

    Dear D_Stranz,
    Rectangle is not child of QGraphicsPixmapItem .This Rectangle and Image from camera(Which is i am drawing on QGraphicsPixmapItem) are childs of QGraphicsScene.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slow Movement of QGraphicsItem

    Rectangle is not child of QGraphicsPixmapItem .This Rectangle and Image from camera(Which is i am drawing on QGraphicsPixmapItem) are childs of QGraphicsScene.
    It still doesn't matter. If you move the rectangle over the pixmap, it will force the pixmap to redraw as different areas are exposed. And if in the process of redrawing the pixmap you are also rescaling it from the camera image, that is a huge amount of work to do every few ms and it gets worse as the number of pixels (size of the pixmap) increases. Try what I suggested: use an overlay widget to draw the ROI so your ROI is not in the same scene (or even in the same graphics view) as the pixmap.

    I would probably not even bother with the G-V architecture for the pixmap part at all - if the pixmap occupies the entire window, then just use a QWidget-based view to display it, and use the G-V architecture in the overlay widget only. If the scene coordinates match the pixmap dimensions, then all the coordinates will be self-consistent.

  12. #12
    Join Date
    Sep 2009
    Posts
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow Movement of QGraphicsItem

    Quote Originally Posted by d_stranz View Post
    It still doesn't matter. If you move the rectangle over the pixmap, it will force the pixmap to redraw as different areas are exposed. And if in the process of redrawing the pixmap you are also rescaling it from the camera image, that is a huge amount of work to do every few ms and it gets worse as the number of pixels (size of the pixmap) increases. Try what I suggested: use an overlay widget to draw the ROI so your ROI is not in the same scene (or even in the same graphics view) as the pixmap.

    I would probably not even bother with the G-V architecture for the pixmap part at all - if the pixmap occupies the entire window, then just use a QWidget-based view to display it, and use the G-V architecture in the overlay widget only. If the scene coordinates match the pixmap dimensions, then all the coordinates will be self-consistent.
    I tried ur solution but its not solving the issue...Iam attaching the zipped files
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. How can QML understand mouse movement?
    By Yonetici in forum Qt Quick
    Replies: 5
    Last Post: 19th July 2012, 09:29
  2. QWidget movement
    By fakefish in forum Qt Programming
    Replies: 8
    Last Post: 19th April 2011, 12:02
  3. Registering QGraphicsItem Movement (Drag)
    By Polnareff in forum Newbie
    Replies: 5
    Last Post: 27th May 2010, 13:41
  4. line movement
    By zgulser in forum Qt Programming
    Replies: 7
    Last Post: 17th August 2009, 18:01
  5. QGraphicsItem recoloring really slow
    By kai in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2008, 07:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.