Results 1 to 2 of 2

Thread: QGraphicsPixmapItem and QGraphicsView::itemAt() issue

  1. #1
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QGraphicsPixmapItem and QGraphicsView::itemAt() issue

    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:

    Qt Code:
    1. QRectF CN_GraphicsOrtophotoItem::boundingRect() const
    2. {
    3. QSizeF size(pixmap().width()*m_xRes, pixmap().height()*m_yRes);
    4. return QRectF(offset(), size);
    5. }
    6.  
    7. void CN_GraphicsOrtophotoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    8. {
    9. painter->drawPixmap(boundingRect().toRect(), pixmap());
    10. }
    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.
    Last edited by alazar; 28th March 2014 at 20:56.

  2. #2
    Join Date
    Mar 2014
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QGraphicsPixmapItem and QGraphicsView::itemAt() issue

    OK, reimplementing the shape() function is the solution.

Similar Threads

  1. QGraphicsView::itemAt() always returns zero
    By tuli in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2013, 20:36
  2. Replies: 0
    Last Post: 5th June 2013, 20:32
  3. Replies: 7
    Last Post: 1st December 2011, 17:24
  4. Replies: 5
    Last Post: 19th November 2011, 23:05
  5. QGraphicsView Render() Issue
    By paul567 in forum Qt Programming
    Replies: 12
    Last Post: 16th November 2007, 13:26

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.