Results 1 to 3 of 3

Thread: Mouse position

  1. #1
    Join Date
    Sep 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Mouse position

    Hi guys, I'm looking for something what can receive me relative x position of mouse after click on image(relative related to picture).
    I printing out pictures on label. Is here any better option? label isn't clickable, so it isn't so easy for me...

  2. #2
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Mouse position

    Either install an EventFilter on the label.

    Qt Code:
    1. class YourEventFilter: public QObject
    2. {
    3. public:
    4. YourEventFilter(QObject *parent):QObject(parent) {}
    5.  
    6. bool eventFilter(QObject *object, QEvent *event);
    7. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ui->label->installEventFilter(new YourEventFilter(this));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. bool YourEventFilter::eventFilter(QObject* object, QEvent* event)
    2. {
    3. if(event->type() == QEvent::MouseButtonPress)
    4. {
    5. QMouseEvent* mEvent = (QMouseEvent*)event;
    6. QPoint point = mEvent.pos();
    7. }
    8. return QObject::eventFilter(object,event);
    9. }
    To copy to clipboard, switch view to plain text mode 


    or simply get the position relatively to window and subtract the label's position.

  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: Mouse position

    You can reimplement mousePressEvent() in a subclass of QLabel.

    Cheers,
    _

Similar Threads

  1. Invert Mouse Position
    By carloval in forum Newbie
    Replies: 0
    Last Post: 21st July 2015, 06:48
  2. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 05:46
  3. Get mouse position on click?
    By N3wb in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2010, 00:33
  4. How to get the mouse's position
    By sophister in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2009, 07:07
  5. How to get mouse's position?
    By coralbird in forum Newbie
    Replies: 4
    Last Post: 23rd July 2006, 04:52

Tags for this Thread

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.