I'm not sure if this will help you but check this function
grabMouse ();
I'm not sure if this will help you but check this function
grabMouse ();
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
i always get a runtime eror when i include this line in my code like that:
Qt Code:
GAMainWindow::GAMainWindow(){ scene = new MapScene(); view = new MapView(scene, this); view->centerOn(1000, 1000); connect(view, SIGNAL(changeFullScreen()), this, SLOT(changeFullScreen())); layout->addWidget(view); view->setMouseTracking(true); view->grabMouse(); panel = new MapPanel(); layout->addWidget(panel); widget->setLayout(layout); setCentralWidget(widget); connect(scene, SIGNAL(sendData(int)), panel, SLOT(showID(int))); }To copy to clipboard, switch view to plain text mode
If I include the mouseGrap like this i get no Runtime error:
Qt Code:
switch (event->key()){ case Qt::Key_B: this->grabMouse(); break; } }To copy to clipboard, switch view to plain text mode
But now the MapView won't get any MouseMoveEvent. The MainWindow still gets them but here the track does not work. I i set MainWindow->setTrackingMouse(true) nothing is different.
It would work if my MainWindow AND my view would be able to track the mouse. Unfortunately they seem to be unable
Do you have any idea why I always get the runtime error when include grapMouse staticly?
Check this link
http://qt.nokia.com/doc/3.3/geometry.html
and the attach example. This will work partially.
The mouse move event will detect global coordinates and put the mouse inseide the cliente area, if he gets near the margins.
The problems his that if the users moves to quiclly the mouse will move outside anyway. And once outside the client area it will not call
the mouse event function.
A workaround could be a timer to call mousemove event, then the mouse will always be put inside the client area.
I remenber doing this in Visualc MFC, there was function SetCapture() that would capture the mouse inside the cliente area, but I didnt find any Qt similar function.
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Thanks for your answers so far. This is basicly what i tried before. Your example works fine for me and I agree with you that one could solve the issue of fast mouse moving with a timer. But if I try to implement this in my program it does not work. I had a look at the debugger and i think my geometry does not work properly. And I think this might be because i did something wrong with the derivation of my classes.
Would it help if I post my whole code here or what informations are required to help me with this issue?
Edit:
I have the problem that the upper and the left margin are ca. as twice as big as the lower and the right margin. Anyone has an idea why this is the case?
Qt Code:
int marginThickness = 30; int globalX = event->globalX(); int globalY = event->globalY(); int geoX = geometry().x(); int geoY = geometry().y(); if (globalY < globalGeo.y() + marginThickness){ newPos.setY(globalGeo.y() + marginThickness); } else if (globalY > globalGeo.y() + height() - marginThickness){ newPos.setY(globalGeo.y() + height() - marginThickness); } if (globalX < globalGeo.x() + marginThickness){ newPos.setX(globalGeo.x() + marginThickness); } else if (globalX > globalGeo.x() + width() - marginThickness){ newPos.setX(globalGeo.x() + width() - marginThickness); } this->cursor().setPos(newPos); }To copy to clipboard, switch view to plain text mode
Last edited by TheClerk; 25th January 2010 at 10:35.
Remove mapToGlobal from line 10, you dont need it sense geometry() is already global. Then check if it works![]()
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
TheClerk (29th January 2010)
I am afraid this does not work. If I remove the mapToGlobal the following happens:
The area that can't be left by the Cursor stays in the top left corner of the screen. If i move the application a bit down and a bit right the boarder to the bottom and to the right become larger and i can leave the application to the top and the left of the frame because it won't get any mouseEvent then.
Edit:
If you want i can send you the whole code zipped. I think this makes things much easier.
Can you show me a printscreen of your game, and point the area where the cursor should be grabbed ?
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Okay. Here we go:
This is how it looks at the moment. All things painted in red are included by me with photoshop and not part of the program. I want to keep the Cursor within the red rectangular. A and B indicate the width and the height of QGraphicsView. C and D show the actual Position of the Cursor in the QGraphicsView. This works correct so far. I just can't get the correct coordinates to set the Cursor when it is close the edge of the widget.
Thanks for your constant help by the way. I am sure we can manage this
Regards,
Simon
I figured it our myself now. Thanks for your help though.
Regards
Bookmarks