[Qt-interest] Overridden wheelEvent not being called

Cole, Derek dcole at integrity-apps.com
Fri Jan 21 18:27:18 CET 2011


Sorry to keep replying to myself..just some thoughts...

Is it possible that the way I am creating the new item, which is within a function, is getting deleted when the function goes out of scope? I have the scene declared as a global variable, but not the ImagePixmapItem. Does it need to be declared globally before I can use it, even after its been put in the scene?


-----Original Message-----
From: Cole, Derek
Sent: Fri 1/21/2011 11:59 AM
To: Cole, Derek; qt-interest at qt.nokia.com
Subject: RE: [Qt-interest] Overridden wheelEvent not being called
 

Some additional information:

This is how I am getting my custom item to the scene:

     QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
     ImagePixmapItem *item = static_cast<ImagePixmapItem *>(scene.addPixmap(p));

     ui->graphicsView->setScene(&scene);
     ui->graphicsView->show();

qi is my QImage, of course.

I tried reimplementing like this to see if I could get any clicks or anything:

#include <QGraphicsPixmapItem>
class ImagePixmapItem: public QGraphicsPixmapItem
    {
    public:
        ImagePixmapItem(const QPixmap &pixmap, QGraphicsItem *parentItem=0);
        ~ImagePixmapItem();
        QPainterPath shape() const;
    protected:
        void wheelEvent ( QGraphicsSceneWheelEvent * event );
        void mousePressEvent(QGraphicsSceneMouseEvent *event);
    };

#include <QPainter>
#include "imagepixmapitem.h"
#include <QGraphicsSceneWheelEvent>

ImagePixmapItem::ImagePixmapItem(const QPixmap &pixmap, QGraphicsItem *parentItem)
: QGraphicsPixmapItem(pixmap,parentItem)
    {
    setCacheMode(NoCache);
    setAcceptHoverEvents(true);
    setFlag(QGraphicsItem::ItemIsSelectable,true);

    }

ImagePixmapItem::~ImagePixmapItem()
    {
    }

   QPainterPath ImagePixmapItem::shape() const
   {
       QPainterPath painterPath;
       painterPath.addRect(boundingRect());
       return painterPath;
   }

   void ImagePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event){
       qDebug("hello");

   }

void ImagePixmapItem::wheelEvent ( QGraphicsSceneWheelEvent * event ){
    qDebug("Print this line if catch a wheelEvent");//this is never printing
    qreal factor = 1.2;
    if (event->delta() < 0)
      factor = 1.0 / factor;
    scale(factor, factor);

}


none of my qDebug statements ever print after I load this image.

What am I doing wrong exactly?



-----Original Message-----
From: qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com on behalf of Cole, Derek
Sent: Fri 1/21/2011 11:09 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Overridden wheelEvent not being called
 

As I was discussing in my other thread - I am trying to get zoom capability on an item being displayed in a QGraphicsView.

I have turned mousetracking on for the QGraphicsView - but do I need to somehow do that for my new QGraphicsPixmapItem?

Heres my header file:

#include <QGraphicsPixmapItem>
class ImagePixmapItem: public QGraphicsPixmapItem
    {
    public:
        ImagePixmapItem(const QPixmap &pixmap, QGraphicsItem *parentItem=0);
        ~ImagePixmapItem();
        QRectF boundingRect() const;
        void paint(QPainter *painter,
                   const QStyleOptionGraphicsItem *option, QWidget *widget=0);
        void setSize(qreal size);
    protected:
        void wheelEvent ( QGraphicsSceneWheelEvent * event );


    private:
        qreal             size;
    };


And I just put a qDebug("Hello"); in the wheelEvent function, yet it seems to never get called. my item does load and display correctly in the QGraphicsView though, it seems


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110121/1aed5bf1/attachment.html 


More information about the Qt-interest-old mailing list