Results 1 to 8 of 8

Thread: Qmouseevent problem

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

    Default Qmouseevent problem

    I read the documentation but couldn't figure out this constructor of QMouseevent
    QMouseEvent::QMouseEvent ( Type type, const QPoint & position, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );

    I want to know what is meant by const QPoint& position in this case and what value should i provide to call the constructor

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

    Default Re: Qmouseevent problem

    I read the documentation but couldn't figure out this constructor of QMouseevent
    what part of:
    The position is the mouse cursor's position relative to the receiving widget.
    didn't you understand?

    I want to know what is meant by const QPoint& position in this case and what value should i provide to call the constructor
    Unless you are overriding some low level Qt stuff, or some similar evil things, you should not have the need to construct your own mouse events - you should get them from the system.

    Maybe if you tell us what you want to achieve we can help you in the right direction.
    ==========================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. The following user says thank you to high_flyer for this useful post:

    ready (21st March 2011)

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

    Default Re: Qmouseevent problem

    actually I want to get mouse coordinate when I click in the picture that I loaded in my ui application using Qlabel

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

    Default Re: Qmouseevent problem

    then you only need to overload the mouse event handler, or install and event filter on the QLabel.
    You do NOT need to create the mouse event object.
    ==========================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.

  6. The following user says thank you to high_flyer for this useful post:

    ready (21st March 2011)

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

    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

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

    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.

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

    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

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

    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.