Results 1 to 15 of 15

Thread: mouse tracking on image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse tracking on image

    Hi wysota, I got it... I used grabWidget to get the image defined in QPixmap

    Thanks...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mouse tracking on image

    Why not inherit QLabel instead of QWidget and just get the pixmap?
    Or even access the image directly as you have it stored as a class member.
    Last edited by wysota; 27th March 2007 at 12:03.

  3. #3
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse tracking on image

    Quote Originally Posted by wysota View Post
    Why not inherit QLabel instead of QWidget and just get the pixmap?
    Or even access the image directly as you have it stored as a class member.
    I'm implementing zooming options also.. The mouse tracking option is one of the feature of the module. I'll get back to you if I get stuck again.

    Thanks and have a good day ahead!!!!!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mouse tracking on image

    I meant to not use grabWidget to get the image as you already have it. Why duplicate it?

  5. #5
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse tracking on image

    Quote Originally Posted by wysota View Post
    I meant to not use grabWidget to get the image as you already have it. Why duplicate it?
    The m_pm pixmap is the image in one window where I move the mouse. Then in other window 'zoomWindow', the area of the mouse pointer covered is shown. For this I need to have a part of m_pm pixmap only. This part is basically the 'pasteRect'

    I used grabwidget to get that part 'pasteRect' of area from m_pm.

    If still I'm wrong anywhere, please correct me. If possible with modification in above code.
    I'll be thankful to you.

    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mouse tracking on image

    Example attached. Scaling needs a little more work, as it ignores margins now (which causes garbage or doesn't allow to see all the image).

    The code is for Qt4, although it should work with Qt3 as well. Just change the included files and the painter scaling and translating code.
    Attached Files Attached Files

  7. The following user says thank you to wysota for this useful post:

    vermarajeev (28th March 2007)

  8. #7
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse tracking on image

    Quote Originally Posted by wysota View Post
    Example attached. Scaling needs a little more work, as it ignores margins now (which causes garbage or doesn't allow to see all the image).

    The code is for Qt4, although it should work with Qt3 as well. Just change the included files and the painter scaling and translating code.
    Hi wysota, thanks once again.

    I saw the example program. I was unable to see the ouput coz of this function

    Qt Code:
    1. void buildImage()
    2. {
    3. const QPixmap *px = lab->pixmap();
    4. int w = qMax(m_pt.x()-(width()/2), 0);
    5. int h = qMax(m_pt.y()-(height()/2), 0);
    6. img = px->copy(w, h, width(), height());
    7. }
    To copy to clipboard, switch view to plain text mode 

    What I think is (might not be correct ) the logic what you have writtten and mine is almost same except that you have used eventFiler and I used mouseMoveEvent.

    The major difference is in the above function. Instead of copy (which is not available in Qt3) I used grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 ), which I think is quite similar to Pixmap::copy in qt4.

    The other best thing about your code was that you used label which I never cared. Anyway it was a good learning experience. Thanks a lot.
    Last edited by vermarajeev; 28th March 2007 at 05:24.

  9. #8
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mouse tracking on image

    Hi wysota!
    I have installed qt4.2.2 on my system and is able to see the output for Example program. It looks good. Thanks!!!!

    Now I should first start porting qt3.x.x to qt4.x.x. What I'l do is first take a sample helloWorld program from qt3 and port it to qt4. Then see what changes I need to make to port qt3 to qt4.

    Have a great day!!!!

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mouse tracking on image

    Quote Originally Posted by vermarajeev View Post
    What I think is (might not be correct ) the logic what you have writtten and mine is almost same except that you have used eventFiler and I used mouseMoveEvent.
    That's not the point, although I think my approach is better as you can "spy" on a widget that doesn't know about it.

    The major difference is in the above function. Instead of copy (which is not available in Qt3) I used grabWidget ( QWidget * widget, int x = 0, int y = 0, int w = -1, int h = -1 ), which I think is quite similar to Pixmap::copy in qt4.
    No, it's not simmilar. You should use QImage::copy() or copyBlt().

    The main difference is I'm accessing the image in question directly, whereas you're grabbing the image by redirecting a paint event.

  11. #10
    Join Date
    Apr 2010
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: mouse tracking on image

    thank you guys for the QEventFilter, i never knew about it it solved my problem.

    regards.

Similar Threads

  1. Replies: 7
    Last Post: 8th September 2006, 16:19
  2. Replies: 2
    Last Post: 24th July 2006, 18:36
  3. setCanvas blocks mouse movement on QtCanvasView
    By YuriyRusinov in forum Qt Programming
    Replies: 8
    Last Post: 20th April 2006, 07:38
  4. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36
  5. [QT3+XP] transparency and mouse tracking
    By incapacitant in forum Newbie
    Replies: 9
    Last Post: 17th February 2006, 18:49

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
  •  
Qt is a trademark of The Qt Company.