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

K. Frank kfrank29.c at gmail.com
Fri Aug 17 04:42:12 CEST 2012

Hi Lincoln!

On Thu, Aug 16, 2012 at 8:13 PM, Lincoln Ramsay
<lincoln.ramsay at nokia.com> wrote:
> 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)

That looks like just the ticket.  I will give it a try.

> 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.

Thanks.  I'll probably use a fixed-size window and just hand-code the

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

Thanks for your help.

K. Frank

More information about the Interest mailing list