Results 1 to 5 of 5

Thread: How can we get current cursor position in any part of window from the child class.

  1. #1
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default How can we get current cursor position in any part of window from the child class.

    we have a class
    Qt Code:
    1. class custom::public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. custom(QWidget *parent)
    6. {
    7.  
    8. }
    9. bool event (QEvent *e)
    10. {
    11. //get cursor position.
    12.  
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 


    suppose we have the above child class. Inside child class event how can we get cursor position irrespective of whether the cursor is on the parent or on the other child of same parent. I have inherited from QObject because i dont want to create any widget in this class just i want to know cursor position to handle other objects.

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

    Default Re: How can we get current cursor position in any part of window from the child class

    Qt Code:
    1. const QPoint p = QCursor::pos();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2011
    Location
    Bangalore, India
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows Symbian S60

    Default Re: How can we get current cursor position in any part of window from the child class

    I have tried that but i am not getting the cursor position.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can we get current cursor position in any part of window from the child class

    You have shown us nothing about how you *use* this custom class. Showing a class definition is meaningless. How can we possibly answer your question without more information?

  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How can we get current cursor position in any part of window from the child class

    QObject::event() is called only when the object receives an event. Make sure the object receives an event.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 2
    Last Post: 20th February 2012, 21:58
  2. QSlider : How to hint current position value ?
    By andre_teprom in forum Newbie
    Replies: 2
    Last Post: 10th August 2011, 01:19
  3. QTableWidget highlight current position in header
    By lalesculiviu in forum Qt Programming
    Replies: 0
    Last Post: 27th February 2010, 19:10
  4. QTextEdit current cursor text format
    By afail in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 14:24
  5. How to know current global mouse position?
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2007, 19:25

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.