LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do I detect a mouse movement in a QImage (https://www.linuxquestions.org/questions/programming-9/how-do-i-detect-a-mouse-movement-in-a-qimage-394481/)

Gnarg 12-19-2005 08:54 AM

How do I detect a mouse movement in a QImage
 
Hi,

I've been trying for a while now to find out if a mouse moves over a QImage object. I can get the mouse movement from the main application but not just the QImage Object which is what I am trying to accomplish.

Anyone know how I can find out? I'm using Kdevelop in KDE 3.4

Gnarg

Hko 12-19-2005 11:20 AM

AFAICS it's not possible to do that, because the virtual mouseMoveEvent() is defined in QWidget which is not one of the parent classes of QImage.

This does makes sense, because a QImage is a in-memory object to hold image-data, and in memory there's no such thing as a mouse pointer...

Gnarg 12-19-2005 12:48 PM

Ah yes, that does make sense. Then I'm not asking the right question.

In order for me to display an image I need to set the clipping rect and then display the image.

Then if I'm asking this right how can I trap mouse movements in the clipping rect?

What I am trying to accomplish is displaying an image in a small part of the application, which is already done. When the mouse moves over this image change the mouse pointer to a cross hair and when it leaves the image restore it. That's it. I'm not really concerned where the mouse is other then if its over the image being displayed.

Even on any widget if I can learn to trap mouse movements then I should be able to learn from that. I've looked at Trolltech example page on mouseEvents and it did not help me to trap mouseMovements for any specific widget, only the main window.



Hope that makes more sense.

Gnarg

foo_bar_foo 12-19-2005 09:44 PM

when you declare your class just set up a handler
i use QCanvasView as an example but any QWidget will work
Code:

class viewer : public QCanvasView {
    Q_OBJECT

public:
    viewer(QCanvas&, QWidget* parent=0, const char* name=0, WFlags f=0);

protected:
    void contentsMousePressEvent(QMouseEvent*);
    void contentsMouseMoveEvent(QMouseEvent*);

now you can handle those events within the QCanvasView
Code:

void viewer::contentsMouseMoveEvent(QMouseEvent* e)
{
}



All times are GMT -5. The time now is 06:13 PM.