Results 1 to 4 of 4

Thread: QGrahpicsScene transform is very slow under Linux

  1. #1
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGrahpicsScene transform is very slow under Linux

    Good day everyone

    I wrote a simple QGraphicsView, QGraphicsSceneapplication that loads image file and add it to QGraphicsPixmapItem, I then can create a selection rectangle using rubber band.

    my main problem is that this works fine under Windows, but under Linux I have 2 situations
    1- if the scene is not zoomed (100%) zoom, it works fine, and I can select the rectangle very fast, and scroll, ..etc very fast
    2- if the scene is zoomed other than 100% (less or more), this becomes very very slow.

    I have attached the full source code for anynoe who likes to give it a try, please feel free to tell me what you think, and what could be the problem for this issue.

    The zooming is done using the transform function

    here is the code for it

    Qt Code:
    1. void SourceScene::transform(qreal zoomFactor, qreal angle)
    2. {
    3. if (!m_imageItem)
    4. return;
    5.  
    6. // we erase selection rect if it exists.
    7. removeSelectionRect();
    8.  
    9. // we compute image center.
    10. qreal imageCenterX = m_imageItem->x()+ m_imageItem->boundingRect().width()/2;
    11. qreal imageCenterY = m_imageItem->y()+ m_imageItem->boundingRect().height()/2;
    12. // we apply the transformation zoom + rotation.
    13. m_imageItem->setTransform(QTransform().translate(imageCenterX, imageCenterY).rotate(angle).scale(zoomFactor, zoomFactor).translate(-imageCenterX, -imageCenterY));
    14. }
    To copy to clipboard, switch view to plain text mode 

    here is the paint function for the seletion rectangle item (QGraphicsPolygonItem item)

    Qt Code:
    1. void SelectionRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. static int i=1;
    4. qDebug("%d SelectionRectItem::paint()", i++);
    5. QColor color = Qt::red;
    6.  
    7. QPen pen(Qt::NoPen);
    8. //pen.setColor(color);
    9. //pen.setWidth(2);
    10. painter->setPen(pen);
    11.  
    12. QBrush brush;
    13. brush.setStyle(Qt::Dense7Pattern);
    14.  
    15. brush.setColor(color);
    16. painter->setBrush(brush);
    17.  
    18.  
    19. QPolygon ply(rg, true);
    20. setPolygon(ply);
    21. painter->drawPolygon(polygon(), fillRule());
    22. //scene()->update(sceneBoundingRect());
    23. }
    To copy to clipboard, switch view to plain text mode 
    I'm not sure if this is the problem or something else

    please if anyone can look at the code, and check what could be the problem, or if anyone has any ideas on how to fix this issue

    To reproduce the effect please choose a pic image over 1 mb size, and then try to zoom in or zoom out, it does not matter, the creation of the selection rectangle will be slow either way

    Best regards
    Attached Files Attached Files
    Last edited by yazwas; 16th March 2010 at 14:20. Reason: added the paint

  2. #2
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGrahpicsScene transform is very slow under Linux

    Hello

    I think I found the problem, its because of this line

    Qt Code:
    1. void SourceScene::transform(qreal zoomFactor, qreal angle)
    2. {
    3. if (!m_imageItem)
    4. return;
    5.  
    6. // we compute image center.
    7. qreal imageCenterX = m_imageItem->x()+ m_imageItem->boundingRect().width()/2;
    8. qreal imageCenterY = m_imageItem->y()+ m_imageItem->boundingRect().height()/2;
    9.  
    10. ///THIS IS THE LINE THAT CAUSES THE ISSUE, THE imageitem is causing the problem and making it very slow.
    11. m_imageItem->setTransform(QTransform().translate(imageCenterX, imageCenterY).rotate(angle).scale(zoomFactor, zoomFactor).translate(-imageCenterX, -imageCenterY));
    12. }
    To copy to clipboard, switch view to plain text mode 

    The definition of the imageitem is below

    #include <QGraphicsPixmapItem>

    Qt Code:
    1. class ImageItem : public QGraphicsPixmapItem
    2. {
    3. public:
    4. ImageItem(const QPixmap & pixmap, QGraphicsItem * parent = 0); ///< ctor
    5.  
    6. virtual ~ImageItem(); ///< dtor
    7.  
    8. QPixmap getImageCutoutPixmap(const QRectF & selectionRect) const; //does something later on, but nothing with the transformation of the page
    9.  
    10. };
    11.  
    12. ImageItem::ImageItem(const QPixmap & pixmap, QGraphicsItem * parent) :
    13. QGraphicsPixmapItem(pixmap, parent)
    14. {
    15. setZValue(0.5);
    16. setCursor(QCursor(Qt::CrossCursor));
    17. }
    To copy to clipboard, switch view to plain text mode 

    its very basic, and I dont know what is the problem with it is. is this a LINUX issue? it only happens in Linux, and I'm not sure what could be the problem.

    ANY COMMENT IS MORE THAN WELCOME

    Best regards

  3. #3
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGrahpicsScene transform is very slow under Linux

    Hello Everyone,

    The problem is only if I dont have the pixmapitem in its original size. i.e. I call the setTransform function when I do zoom in/out. if the zoom = 1, it works extremley well even if the page is very large. what could be the problem?

    guys, any response, anyone thinks it cant be solved, just tell me, any long shot suggestions
    anyone hellllp

  4. #4
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGrahpicsScene transform is very slow under Linux

    Hello all

    if I use -graphicssystem raster as parameter, it works fine
    i.e.
    ./myapp -graphicssystem raster

Similar Threads

  1. transform() vs pos() for QGraphicsItem
    By aalexei in forum Qt Programming
    Replies: 9
    Last Post: 13th November 2012, 23:34
  2. Distance Transform on a QImage
    By Franckesh in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 08:58
  3. How to transform image like warp
    By yycking in forum Qt Programming
    Replies: 2
    Last Post: 10th December 2009, 08:35
  4. How can I added a button to QGrahpicsScene
    By learning_qt in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2009, 08:51
  5. understanding QwtPlot::transform()
    By b.mourat in forum Qwt
    Replies: 1
    Last Post: 25th May 2008, 07:43

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.