[Interest] How to make a button dodge being clicked?

Lincoln Ramsay lincoln.ramsay at nokia.com
Fri Aug 17 02:13:33 CEST 2012


On 08/17/2012 09:09 AM, ext K. Frank wrote:
> What would be a good strategy to make a button move to another
> location when approached by the mouse?

Create your button as normal but don't put it in a layout. Instead, 
position it manually (this means you'll need a fixed window size or code 
to reposition the button in resizeEvent).

Then just track the mouse(1) and when it gets close to your button, 
change it's x and y properties to move it.

1) http://doc.qt.nokia.com/4.7-snapshot/qwidget.html#mouseTracking-prop)


It may be simpler to start with the button in a layout until the mouse 
first gets close (then remove it from the layout when you want to move 
it). That way you don't need to determine the initial position of the 
button yourself.

-- 
Lincoln Ramsay - Senior Software Engineer
Qt Development Frameworks, Nokia - http://qt.nokia.com/



More information about the Interest mailing list