Results 1 to 14 of 14

Thread: how can we get the coordinate of desktop when mouse is placed on a particular poin

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default how can we get the coordinate of desktop when mouse is placed on a particular poin

    hai all,


    how can we get the coordinate of desktop when mouse is placed on a particular point of desktop?
    Can someone help me ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular


  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    We need the cursor position on the desktop while the application is running.
    In our project we need to apply magnetic effects on desktop widgets.When we drag the widget to the right edge of the desktop it move to the right edge and hide from the desktop(its working fine in our application). We need the widget to pop- up from the right of the desktop to the left if we slide the mouse on the right edge of the desktop.We need to check whether the current cursor position is on the right edge of desktop. How can we do this?





    Qt Code:
    1. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if (event->type() == QEvent::MouseMove)
    4. {
    5. QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    6. qDebug()<<"Mouse Move event...."<<mouseEvent->pos().x()<<mouseEvent->pos().y();
    7. }
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 


    This code works fine inside the widget but don't get the coordinates outside the widget. We need to get the cursor coordinates on desktop
    Last edited by vinayaka; 18th January 2012 at 08:51. Reason: updated contents

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    Either grabMouse() (but then nobody else will receive the events) or periodically poll the cursor position using QCursor::pos(), however this will be inefficient and will probably worsen your user experience. The proper approach would be to hook into the native event system to be notified upon interesting events.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    We dont get you?
    The proper approach would be to hook into the native event system to be notified upon interesting events.
    plz specify briefly?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    Briefly speaking -- use WinAPI.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    I'm not sure I've understood you well but I think you want to be able to drag window to the right edge of the desktop and then make it pop from the left, right?

    If that's the case then it's simple:
    Qt Code:
    1. void MainWindow::moveEvent( QMoveEvent* )
    2. {
    3. QRect dr = QApplication::desktop()->rect();
    4. QPoint mp = QCursor::pos();
    5.  
    6. if( mp.x() > dr.right() - 5 )
    7. {
    8. dr.moveLeft( 0 );
    9. mp.setX( 0 );
    10.  
    11. this->move( dr.topLeft() );
    12. QCursor::setPos( mp );
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    If that's not the case then I don't know what you want to achieve.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    I think the requirement is to build a "menu" app that normally is invisible, but slides out from the RHS of the desktop when the mouse pointer is pushed to the RHS of the desktop. Presumably the app will slide back off the RHS of the desktop when the mouse pointer is no longer over it.

    It seems to me that a peek at QCursor::pos() every 250ms or so (using QTimer) is the easiest way. If the cursor is against the edge in two consecutive checks then pop up. Elegant? Maybe not.

    Another approach might be to leave a (transparent?) borderless, always-on-top widget a few pixels wide on the desktop RHS and look for mouse move events on it.

  10. #10
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    thank you all for your valuable suggestion.Here I am attaching a sample video that show the interaction of Widget.we need to apply the effects like in video.How can we do the same?
    Last edited by vinayaka; 20th January 2012 at 12:39.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    So you want a sheet-like behavior. For hiding you can use leaveEvent(), for showing I think Chris has already given you a possible solution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    can anyone please send the sample code for applying these effects into our Widget?

  13. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    How about you show us what you have tried?

  14. #14
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how can we get the coordinate of desktop when mouse is placed on a particular

    Qt Code:
    1. QDesktopWidget *desktop = QApplication::desktop();
    2. screenWidth1 = desktop->width();
    3. screenHeight1 = desktop->height();
    4. x1 = screenWidth1-400;
    5. y1 = screenHeight1-675;
    6. QTimer *cursor_Pos = new QTimer(this);
    7. connect(cursor_Pos, SIGNAL(timeout()), this, SLOT(updatePos()));
    8. cursor_Pos->setInterval(250);
    9. cursor_Pos->start();
    10.  
    11. void RightSideBar::updatePos()
    12. {
    13. dr = QApplication::desktop()->rect();
    14. QPoint mp = QCursor::pos();
    15. int cursor_check;
    16. cursor_check=QApplication::desktop()->width()-this->width();
    17. if( mp.x() > dr.right() - 10&&this->isVisible()&&cursorRight==true)
    18. {
    19. qDebug()<<"Cursor on Right Edge of desktop!!!";
    20. cursorRight=false;
    21. cursorLeft=true;
    22. widgetRight=true;
    23.  
    24. this->setGeometry(x1+52,y1,340,screenHeight1-200);
    25.  
    26. }
    27. if(this->width()+this->x()>dr.right() - 10&&this->isVisible()&&widgetRight==true)
    28. {
    29. qDebug()<<"Widget on Right Edge of desktop!!!";
    30. widgetRight=false;
    31. cursorRight=true;
    32. this->setGeometry(this->width()+this->x()*2,this->y(),340,screenHeight1-200);
    33.  
    34.  
    35. }
    36. if(cursor_check>mp.x()&&this->isVisible()&&cursorLeft==true)
    37. {
    38. qDebug()<<"Cursor Position is less then Widget Position";
    39. cursorLeft=false;
    40. cursorRight=true;
    41. this->setGeometry(this->width()+this->x()*2,this->y(),340,screenHeight1-200);
    42.  
    43. }
    44.  
    45. }
    To copy to clipboard, switch view to plain text mode 

    First and third conditions are working fine in our application.In this code second condition is not working properly.How can we rectify the issues?

Similar Threads

  1. Coordinate confusion
    By onurozcelik in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2010, 09:42
  2. coordinate system
    By Wojtek.wk in forum Newbie
    Replies: 7
    Last Post: 12th April 2010, 13:47
  3. coordinate problem
    By sai in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 10:21
  4. Replies: 5
    Last Post: 31st January 2009, 07:36
  5. Replies: 7
    Last Post: 14th October 2007, 22:04

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.