Results 1 to 11 of 11

Thread: Adding mouse event tracking to a QLabel contained in a main window

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    18
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Adding mouse event tracking to a QLabel contained in a main window

    I have created a main window with Qt Creator containing a QLabel named tracking_frame ...

    How would I add mouse tracking to this QLabel only? - for example, outputting the coordinates (with respect to the QLabel) of a mouse click within the label.

    I realise that I need to overwrite the protected member function: void mousePressEvent(QMouseEvent *event) inside tracking_frame and then create a function like so:

    Qt Code:
    1. void ??? ::mousePressEvent(QMouseEvent *event)
    2. {
    3. fprintf(stderr,"(x,y)=(%d,%d)\n",event->pos().x(),event->pos().y());
    4. } // mousePressEvent()
    To copy to clipboard, switch view to plain text mode 

    I am just unsure of where to place the
    Qt Code:
    1. protected:
    2. void mousePressEvent(QMouseEvent *event);
    To copy to clipboard, switch view to plain text mode 
    (as the QLabel class definition is inside "ui_MainWindow.h" as it was all created in Qt Creator):

    If I place it in the MainWin class definition in MainWindow.h the mouse tracking works but of course for anywhere in the main window...

    What do I have to do?

    I hope someone can help me out with this!
    Hopefully it is a fairly straightforward procedure

    Cheers!
    Last edited by dmginc; 17th January 2010 at 09:00.

  2. The following user says thank you to dmginc for this useful post:

    ready (25th March 2011)

Similar Threads

  1. mouse tracking on image
    By vermarajeev in forum Qt Programming
    Replies: 14
    Last Post: 12th May 2010, 13:06
  2. Mouse tracking outside the application interface
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 2nd May 2009, 06:44
  3. mouse tracking in QGraphicsItem
    By christina123y in forum Qt Programming
    Replies: 10
    Last Post: 9th March 2009, 08:23
  4. Adding scroll bars to a main window
    By dougab in forum Newbie
    Replies: 9
    Last Post: 25th December 2007, 20:27
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.