[Qt-interest] paint on QGraphicsView

Mihail Naydenov mlists at ymail.com
Tue Jun 8 09:09:00 CEST 2010



>
>From: caius ligarius <caius9090 at gmail.com>
>To: Qt Interest <qt-interest at trolltech.com>
>Sent: Tue, June 8, 2010 1:51:02 AM
>Subject: [Qt-interest] paint on QGraphicsView
>
>>Hi,
>
>I have a QGraphicsView widget which is used to display an image from a QImage pointer (pseudo code below). 
>
>1) What is the best way to paint pixels on the viewport for the "current image" which is displayed (example: draw lines, points etc.) 

Use a QGraphicsItem subclass and reimplement paint(). Draw lines. point etc. there.
(You can also reimplement QGraphicsView::drawForegrond to paint "on" the viewport (above all items))

>>2) What is the quickest way to update an existing QImage data buffer ? (I tried using setpixel but it's too slow!)

Either use QPainter with QImage as source.
or
Access QImage bits() and draw manually.

To display onscreen you either drawImage() and get the image immediately shown, but draw/redraw is slower
or
Convert to pixmap first for *fast* draw/redraw, but paying the price for both time for conversion and, for *big* images - double memory consumption.

MihailNaydenov

>
>void Class:: DisplayImage(QImage* currImg)
>{
>     QPixmap np = QPixmap::fromImage(*currImg);
>
>     graphicpixmapitem->setPixmap(np);
>     graphicsscene->setSceneRect(0, 0, currImg->width(), currImg->height());
>     graphicsscene->addItem(graphicitemSingleView);
>
>     ui.graphicsView->setScene(graphicssceneSingleView);
>>     ui.graphicsView->show();
>}
>
>graphicpixmapitem: is QGraphicsPixmap class member variable
>graphicsscene: is QGraphicsScene class member variable
>ui.graphicsView: is QGraphicsView class member variable
>
>
>Thanks,
>Caius
>
>


      



More information about the Qt-interest-old mailing list