Hi all,
I need to load georreferenced images in my program. To do it, I use GDAL library to obtain a QImage* and then, I create a QGraphicsPixmapItem from that image.
Because of the pixel resolution and to avoid resampling of the image, I have a subclass of QGraphicsPixmapItem where boundingRect() and paint() methods are reimplemented as follows:
QRectF CN_GraphicsOrtophotoItem
::boundingRect() const {
QSizeF size
(pixmap
().
width()*m_xRes, pixmap
().
height()*m_yRes
);
return QRectF(offset
(), size
);
}
{
painter->drawPixmap(boundingRect().toRect(), pixmap());
}
QRectF CN_GraphicsOrtophotoItem::boundingRect() const
{
QSizeF size(pixmap().width()*m_xRes, pixmap().height()*m_yRes);
return QRectF(offset(), size);
}
void CN_GraphicsOrtophotoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawPixmap(boundingRect().toRect(), pixmap());
}
To copy to clipboard, switch view to plain text mode
where m_xRes and m_yRes are the pixel resolutions (in m/pixel).
It works fine, but know I have a trouble: QGraphicsView::itemAt() doesn't work properly, because if the pixel resolution is 2 m/pixel (for example), then itemAt() method only works on the top left quarter of the image, and so on.
I thought itemAt() called boundingRect(), but now I'm not sure... Could anybody help me?
Thanks in advance.
Bookmarks