Results 1 to 8 of 8

Thread: Qmouseevent problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    30

    Default Re: Qmouseevent problem

    then you only need to overload the mouse event handler, or install and event filter on the QLabel.
    please elaborate your explanation .........
    how to install and event filter on the QLabel

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Qmouseevent problem

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2011
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    30

    Default Re: Qmouseevent problem

    I am getting really confused please help me how to install installEventFilter for Qlabel........
    I just want to get the co-ordinate in my lineedit when I click in qlabel

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: Qmouseevent problem

    Which part of documentation is not clear to you ?
    In order to install event filter on a QLabel you need to call:
    Qt Code:
    1. MyClass * filterObject = new MyClass(); // MyClass is a subclass of QObject
    2. ...
    3. QLabel * label = new QLabel();
    4. label->installEventFilter(filterObject);
    To copy to clipboard, switch view to plain text mode 
    After that you will be able to catch all the events that goes to label object by reimplementing virtual bool eventFilter( QObject * obj, QEvent * ev ) in filterObject class:
    Qt Code:
    1. bool MyClass::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (obj == label) {
    4. //... test if the event is MousePress and do something with it
    5. } else {
    6. // pass it to the parent class
    7. return QObject::eventFilter(obj, event);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    I've almost copied the example from docs.

Similar Threads

  1. how to catch qMouseEvent
    By pakine in forum Newbie
    Replies: 4
    Last Post: 27th June 2012, 10:47
  2. QMouseEvent on QPaintEvent
    By GUIman in forum Newbie
    Replies: 7
    Last Post: 1st March 2011, 08:51
  3. QMouseEvent
    By Fallen_ in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2010, 05:17
  4. QMouseEvent
    By shenakan in forum Newbie
    Replies: 1
    Last Post: 20th August 2009, 14:53
  5. qmouseEvent handling
    By nass in forum Qt Tools
    Replies: 9
    Last Post: 13th October 2006, 08:55

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.