[Qt-interest] paint on QGraphicsView

caius ligarius caius9090 at gmail.com
Tue Jun 8 09:23:10 CEST 2010


Thanks.

If possible can  you point me to or give me a simple example for
implementing (1) & (2)?

Also for (1) do I need to explicitly call paint()?

Caius

On Tue, Jun 8, 2010 at 12:09 AM, Mihail Naydenov <mlists at ymail.com> wrote:

>
>
> >
> >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
> >
> >
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100608/c235bffc/attachment.html 


More information about the Qt-interest-old mailing list