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 ?
Re: how can we get the coordinate of desktop when mouse is placed on a particular
Re: how can we get the coordinate of desktop when mouse is placed on a particular
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?
Code:
{
if (event
->type
() == QEvent::MouseMove) {
QMouseEvent *mouseEvent
= static_cast<QMouseEvent
*>
(event
);
qDebug()<<"Mouse Move event...."<<mouseEvent->pos().x()<<mouseEvent->pos().y();
}
return false;
}
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
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.
Re: how can we get the coordinate of desktop when mouse is placed on a particular
We dont get you?
Quote:
The proper approach would be to hook into the native event system to be notified upon interesting events.
plz specify briefly?
Re: how can we get the coordinate of desktop when mouse is placed on a particular
Briefly speaking -- use WinAPI.
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:
Code:
{
if( mp.x() > dr.right() - 5 )
{
dr.moveLeft( 0 );
mp.setX( 0 );
this->move( dr.topLeft() );
}
}
If that's not the case then I don't know what you want to achieve.
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.
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?http://www.youtube.com/watch?v=jcopj...ature=youtu.be
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.
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?
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?
Re: how can we get the coordinate of desktop when mouse is placed on a particular
Code:
screenWidth1 = desktop->width();
screenHeight1 = desktop->height();
x1 = screenWidth1-400;
y1 = screenHeight1-675;
connect(cursor_Pos, SIGNAL(timeout()), this, SLOT(updatePos()));
cursor_Pos->setInterval(250);
cursor_Pos->start();
void RightSideBar::updatePos()
{
int cursor_check;
cursor_check
=QApplication::desktop()->width
()-this
->width
();
if( mp.x() > dr.right() - 10&&this->isVisible()&&cursorRight==true)
{
qDebug()<<"Cursor on Right Edge of desktop!!!";
cursorRight=false;
cursorLeft=true;
widgetRight=true;
this->setGeometry(x1+52,y1,340,screenHeight1-200);
}
if(this->width()+this->x()>dr.right() - 10&&this->isVisible()&&widgetRight==true)
{
qDebug()<<"Widget on Right Edge of desktop!!!";
widgetRight=false;
cursorRight=true;
this->setGeometry(this->width()+this->x()*2,this->y(),340,screenHeight1-200);
}
if(cursor_check>mp.x()&&this->isVisible()&&cursorLeft==true)
{
qDebug()<<"Cursor Position is less then Widget Position";
cursorLeft=false;
cursorRight=true;
this->setGeometry(this->width()+this->x()*2,this->y(),340,screenHeight1-200);
}
}
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?