Results 1 to 3 of 3

Thread: Accessing Event Arguments?

  1. #1
    Join Date
    Dec 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Accessing Event Arguments?

    Hi all,

    In C#, when using an event handler, it will have a specific name (eg: "onPressEvent mouseclick()" - and you can then access various properties by calling mouseclick.etc() - in C++/QT I have:

    Qt Code:
    1. void MapViewer::mousePressEvent(QMouseEvent *event)
    To copy to clipboard, switch view to plain text mode 

    However, I don't know how to access event or any of its methods, like documented here: http://doc.qt.digia.com/qt/qmouseeve...blic-functions

    Can anybody shed any light on this?

    Regards,
    Ben.

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing Event Arguments?

    class QMouseEvent has been passed as an argument. Use it to access properties of QMouseEvent.
    Supposing MapViewer is a subclass of QWidget and you have reimplemented the mousePressEvent, then all the mouse press events on widget will have your reimplemented function called.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Accessing Event Arguments?

    As pkj said, you have the event as a function argument and it is a normal object, so methods are called like on any other C++ object
    Qt Code:
    1. QPoint position = event->pos(); // where inside your widget the press happend
    2.  
    3. switch ( event->button() ) {
    4. case Qt::LeftButton: // left button pressed
    5. break;
    6. case Qt::RightButton: // right button pressed
    7. break;
    8. case Qt:MiddleButton: // middle button pressed
    9. break;
    10.  
    11. default: // dont care
    12. break;
    13. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. CustomContextMenu with arguments
    By toodles in forum Newbie
    Replies: 3
    Last Post: 27th June 2012, 14:25
  2. slots with arguments
    By marco.stanzani in forum Newbie
    Replies: 5
    Last Post: 24th March 2011, 12:05
  3. QApplication Arguments
    By ToddAtWSU in forum Qt Programming
    Replies: 0
    Last Post: 27th January 2011, 17:34
  4. how to use arguments in Qt?
    By mr_kazoodle in forum Newbie
    Replies: 5
    Last Post: 26th January 2011, 21:04
  5. QProcess Arguments
    By doggrant in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2010, 17:45

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.