Results 1 to 4 of 4

Thread: Displaying an image that is being generated in realtime

  1. #1
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    3

    Default Displaying an image that is being generated in realtime

    Hi,

    I am writing a simple scanline renderer, and would like to draw the image as it's generated, line by line.

    I am using QGraphicsScene in order to display it. I am having two problems:

    - QGraphicsScene only accepts QPixmaps, and I am unable to find a way of drawing pixels into them (apart from converting them into QImages).
    - I cannot find a way of painting over a QPixmap that is part of a QGraphicsScene. There is a way of doing so?

    Maybe there is other way of doing this, any comments are welcome.

    Thanks in advance,
    Jorge

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Displaying an image that is being generated in realtime

    I think you can do this with a QGraphicsView too.
    Build a custom QGraphicsPixmapItem that holds an additional QImage and the current scanline. The QIMage needs to be initialized to the item size(in pixels)

    Every time the renderer gives you a rendered buffer, compute the current scan line and set it in the QImage with QImage::scanLine. In the same time, update the item's pixmap from the QImage and also update the portion of the item that was invalidated by the new lines( by calling QGraphicsItem::update(const QRectF&)). You will get the desired rendering effect.

    Another solution is to use a widget and a QImage as paint devices, but the implementation would be pretty much the same.

    Regards

  3. The following user says thank you to marcel for this useful post:

    IrYoKu (25th August 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    3

    Default Re: Displaying an image that is being generated in realtime

    Quote Originally Posted by marcel View Post
    In the same time, update the item's pixmap from the QImage
    You mean update the QGraphicsPixmapItem internal pixmap with the QImage of my custom class? If yes, how can I access the internal pixmap? Or maybe I have to replace it completely using QGraphicsPixmapItem::setPixmap?

  5. #4
    Join Date
    Apr 2007
    Posts
    10
    Thanks
    3

    Default Re: Displaying an image that is being generated in realtime

    Finally I managed to solve this problem by creating a derived class from QGraphicsItem and implementing boundingRect and paint. Very easy stuff.

Similar Threads

  1. Replies: 7
    Last Post: 27th June 2007, 09:34
  2. displaying png image for a given area..
    By sar_van81 in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 13:56
  3. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.