[Qt-interest] Restricting Mouse Movements
Ender EREL
erelender at yahoo.com
Tue Sep 8 08:25:05 CEST 2009
I don't know if there is an automatic way to do this but i don't think
so. You can achieve this by following these steps:
1 - Override mouseMoveEvent(QMouseEvent* event)[1] for your widget.
2 - In the overridden mouseMoveEvent, check if the mouse position is
outside the allowed area. If it is, set the cursor position[2] to the
nearest position inside your area.
The widget will normally recieve mouseMoveEvents only if a mouse button
is down by default. You can recieve mouseMoveEvents when a mouse button
is not down by calling setMouseTracking(true)[3] on your widget.
[1] - http://doc.trolltech.com/4.5/qwidget.html#mouseMoveEvent
[2] - http://doc.trolltech.com/4.5/qcursor.html#setPos-2
[3] - http://doc.trolltech.com/4.5/qwidget.html#mouseTracking-prop
--
Ender EREL
More information about the Qt-interest-old
mailing list