[Qt-interest] QGraphicsView::mouseMoveEvent not called after view tranform change (Qt-4.5.2)

Lorenzo Masini lorenxo86 at gmail.com
Thu Feb 4 15:51:39 CET 2010


Il giorno gio, 04/02/2010 alle 15.19 +0900, r ha scritto:
> I'm reimplementing QGraphicsView::mouseMoveEvent to detect mouse hover
> on certain items. This works fine unless I change the view transform
> (e.g. move or rescale the view with a keyboard action). Since this
> doesn't trigger the execution of the mouseMoveEvent method my visual
> hover indicators are no longer in sync with the actual mouse cursor
> position. Tested with Qt-4.5.2.
> 
> Would it be possible to emit such an event in future versions of Qt?
> What would be the best work-around for Qt-4.5/4.6? I imagine I can
> simply manually emit such an event from the code changing view
> transform.

Why don't you reimplement QGraphicsScene::mouseMoveEvent()?
Another solution could be QGraphicsItem::setCursor() on the items you
are intrested.
In this way when you hover an item the cursor changes to the one you
selected. 

For example:

class Item : public QGraphicsItem
{
public:
	Item::Item(QGraphicsItem *parent = 0) : QGraphicsItem(parent) {
		setCursor(Qt::CrossCursor);

	}
};

or simply when you create the the item:

QGraphicsPixmapItem *item = scene->addPixmap(pixmap);
item->setCursor(Qt::CrossCursor);

cheers
Lorenzo







More information about the Qt-interest-old mailing list