Results 1 to 8 of 8

Thread: Problem getting mouse events from overrider QGraphicsPixmapItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    22
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem getting mouse events from overrider QGraphicsPixmapItem

    Hello,

    I would like to use my own implementation of QGraphicsPixmapItem so that I can do things during the mouse events like zoom the image, etc.

    here is my class:

    Qt Code:
    1. #include <QPainter>
    2. #include "imagepixmapitem.h"
    3. #include <QGraphicsSceneWheelEvent>
    4.  
    5. ImagePixmapItem::ImagePixmapItem(const QPixmap &pixmap, QGraphicsItem *parentItem)
    6. : QGraphicsPixmapItem(pixmap,parentItem)
    7. {
    8. setCacheMode(NoCache);
    9. setAcceptHoverEvents(true);
    10. setFlag(QGraphicsItem::ItemIsSelectable,true);
    11.  
    12. }
    13.  
    14. ImagePixmapItem::~ImagePixmapItem()
    15. {
    16. }
    17.  
    18. QPainterPath ImagePixmapItem::shape() const
    19. {
    20. QPainterPath painterPath;
    21. painterPath.addRect(boundingRect());
    22. return painterPath;
    23. }
    24.  
    25. void ImagePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event){
    26. qDebug("hello");
    27.  
    28. }
    29.  
    30. void ImagePixmapItem::wheelEvent ( QGraphicsSceneWheelEvent * event ){
    31. qDebug("Print this line if catch a wheelEvent");//this is never printing
    32. qreal factor = 1.2;
    33. if (event->delta() < 0)
    34. factor = 1.0 / factor;
    35. scale(factor, factor);
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

    And here is where I create a new ImagePixmapItem:

    Qt Code:
    1. QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
    2. ImagePixmapItem *item = static_cast<ImagePixmapItem *>(scene.addPixmap(p));
    3.  
    4. ui->graphicsView->setScene(&scene);
    5. ui->graphicsView->show();
    To copy to clipboard, switch view to plain text mode 

    where qi is my image.

    This loads correctly intot he graphicsView, but it does not seem to give me any of the mouse debug outputs.

    Any ideas what is wrong?
    Last edited by high_flyer; 21st January 2011 at 18:37. Reason: code tags

Similar Threads

  1. problem propagating mouse events.
    By ngc_1729 in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2010, 15:11
  2. Mouse events in QGraphicsPixmapItem and QGraphicsTextItem
    By manojmka in forum Qt Programming
    Replies: 3
    Last Post: 8th August 2008, 12:38
  3. Problem in Mouse Press Events & Vectors
    By dheeraj in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 19:08
  4. problem about mouse button events
    By vql in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 11:14
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 07:13

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.