Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, December 2006
overlay painting in QScrollArea


Message 1 in thread

I'm working on writing yet another geospatial imagery viewing application.
Since I have to deal with large images, I've already created a subclass of
QWidget specifically for rendering QImage's. I can readily put that into a
QScrollArea without any problems.

I would like to add a compass-rose as an overlay on the image displayed
within my scroll area. It would have to be rendered in a fixed position
(say, in the upper right corner) as the user scrolls around the image. I've
have no qualms about subclassing QScrollArea, and re-implementing the
paintEvent (but I'm not sure if that's what's necessary. A simple yes/no
will point me in the right direction.)

I've googled extensively, but haven't been able to find anything very
informative, much less any examples from which to bootstrap myself.

--
 [ signature omitted ] 

Message 2 in thread

Eric the Fruitbat wrote:

> I'm working on writing yet another geospatial imagery viewing application.
> Since I have to deal with large images, I've already created a subclass of
> QWidget specifically for rendering QImage's. I can readily put that into a
> QScrollArea without any problems.
> 
> I would like to add a compass-rose as an overlay on the image displayed
> within my scroll area. It would have to be rendered in a fixed position
> (say, in the upper right corner) as the user scrolls around the image.
> I've have no qualms about subclassing QScrollArea, and re-implementing the
> paintEvent (but I'm not sure if that's what's necessary. A simple yes/no
> will point me in the right direction.)
> 
> I've googled extensively, but haven't been able to find anything very
> informative, much less any examples from which to bootstrap myself.


Ok, so I went ahead and subclassed QScrollArea, re-implementing the
paintEvent as so.

void myScrollArea::paintEvent(QPaintEvent* event)
{
    QScrollArea::paintEvent(event);
    QPainter painter(viewport());

    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap));
    painter.setBrush(QBrush(Qt::green, Qt::SolidPattern));
    painter.drawEllipse(80,80,200,240);

}

I call the base class paintEvent method first, and then proceed to draw on
the viewport. Unfortunately this paints the ellipse behind the image. Is
there any way to paint in the foreground? so that I can draw in a fixed
position, and have it display on top of the image?

--
 [ signature omitted ]