Results 1 to 2 of 2

Thread: How to shift the pixels of part of a QGraphicsItem?

  1. #1
    Join Date
    Jan 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default How to shift the pixels of part of a QGraphicsItem?

    I would like to know whether it is possible to shift part of a drawing by copying its pixels rather than redrawing it.

    I work in an embedded environment, where performance is a key factor. We use Qt 4.8.

    I have a set of real-time data points that I want to draw. I define the following class:

    Qt Code:
    1. class SetOfDataPoints : public QGraphicsItem
    2. {
    3. public:
    4. <constructor>
    5. QRectF boundingRect() const { ... }
    6. void paint(QPainter* painter,
    7. const QStyleOptionGraphicsItem* option,
    8. QWidget* widget = NULL) { ... }
    9. <other methods>
    10. };
    To copy to clipboard, switch view to plain text mode 

    At regular intervals, I read a new data point, add it to the instance of SetOfDataPoints, and shift the SetOfDataPoints to the left (by calling QGraphicsItem::moveBy() on the SetOfDataPoints), so the new data point becomes visible. As a result, SetOfDataPoints::paint() gets called, and in that method I have to draw the entire set of data points. The drawing currently consists only of line segments that connect the data points, but will become more elaborate in the future.

    Now, it feels inefficient to redraw the whole set of data points, when most of the graph is actually just shifted to the left. I would like to shift the pixels of the unchanged part of the graph to the left, and draw only the one line segment that connects the last two points. At least I would like to try, and measure how much that improves performance.

    Is there a way to do that in Qt 4.8?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to shift the pixels of part of a QGraphicsItem?

    What you could try is to draw your data into a buffer, say a QImage, and only paint that image in paint().

    That way when you get new data, you could resize the image, paint the new bits.
    Or keep the size of the image, shift part of the image and paint the now vacant bits.

    Cheers,
    _

Similar Threads

  1. Replies: 9
    Last Post: 13th June 2012, 15:42
  2. add pixels to qgraphicsitem
    By mcarter in forum Qt Programming
    Replies: 20
    Last Post: 28th February 2011, 23:37
  3. Replies: 5
    Last Post: 23rd January 2011, 11:27
  4. Display part of image on a smaller QGraphicsItem
    By biplab.project in forum Qt Programming
    Replies: 0
    Last Post: 5th January 2011, 10:03
  5. QGraphicsItem mousePressEvent only on opaque pixels
    By jonks in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2010, 10:24

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.