[Qt-interest] QMainWindow: Prevent mouse from leaving.

John McClurkin jwm at nei.nih.gov
Tue Oct 27 17:34:00 CET 2009


Martin Guillon wrote:
> Thanks a lot for your answer Rene,
> 
> I already tried the mouseMoveEvent trick with mousetracking. In it i set the position of the mouse to the middle of my window.
> My problem is that when the mouse move too fast, the mouse is out of the window before you can receive the mousemoveevent. And so the application will lose the focus.
> I just retried the grabmouse trick on my mainwindow and it doesn’t work. iF I move fast the mouse gets out and the application loses the focus. It comes back as soon as the pointer get back over the window.
> 
> Any other idea ? :P
> 
> -----Message d'origine-----
> De : qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] De la part de R. Reucher
> Envoyé : Tuesday, October 27, 2009 4:37 PM
> À : qt-interest at trolltech.com
> Objet : Re: [Qt-interest] QMainWindow: Prevent mouse from leaving.
> 
> On Tue, 27 Oct 2009 16:30:32 +0100, Martin Guillon wrote:
>> Doesn’t work for a qmainwindow.
> Why not?
> 
>> It wont prevent the mouse from leaving the window.
> If you really want to prevent the mouse cursor from "visually" leaving 
> the widget, you should enable mouseTracking and catch the QWidget's 
> mouseMoveEvent()... ignore()'ing a move-event outside the widget.
> 
>> Moreover it wont event send mouse move event when the mouse
>> is out of the mainwindow.
> AFAICT, it will, because mouse events are "grabbed" by that widget.
> 
>> And finally I want to hide the cursor. With grab the cursor can still
>> leave the window and so wont be transparent.
> See above.
> 
> HTH, René
Set your application to run in full screen mode. This will also prevent 
viewing other parts of the desktop. It might be disturbing to a user to 
be unable to access applications that are on the desktop.



More information about the Qt-interest-old mailing list