Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-19-2005, 08:54 AM   #1
Registered: Feb 2004
Location: Canada
Distribution: Gentoo Linux
Posts: 44

Rep: Reputation: 15
How do I detect a mouse movement in a QImage


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

Old 12-19-2005, 11:20 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
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...
Old 12-19-2005, 12:48 PM   #3
Registered: Feb 2004
Location: Canada
Distribution: Gentoo Linux
Posts: 44

Original Poster
Rep: Reputation: 15
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.

Old 12-19-2005, 09:44 PM   #4
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
when you declare your class just set up a handler
i use QCanvasView as an example but any QWidget will work
class viewer : public QCanvasView {

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

    void contentsMousePressEvent(QMouseEvent*);
    void contentsMouseMoveEvent(QMouseEvent*);
now you can handle those events within the QCanvasView
void viewer::contentsMouseMoveEvent(QMouseEvent* e)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse Movement Problem in DOSbox smannell Linux - Software 14 06-14-2009 03:35 PM
System reboots from mouse movement 24jedi Linux - Hardware 2 06-03-2005 08:42 AM
Choppy mouse movement with xorg 6.7.0-11 tommyr1216 Linux - Hardware 5 01-23-2005 12:48 AM
SlackWare 9.1 Mouse-Constant Movement Zero-0-Effect Slackware 6 12-21-2003 07:43 AM
Optical mouse and choppy movement sienarot Linux - Hardware 7 07-06-2003 06:11 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration