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

André Somers andre at familiesomers.nl
Fri Aug 17 07:40:14 CEST 2012



Op 17 aug. 2012 om 02:13 heeft Lincoln Ramsay <lincoln.ramsay at nokia.com> het volgende geschreven:

> 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 
For more effect, you might want to use QPropertyAnimation instead of directly moving the button. By animating the geometry property, you can get funny effects. 

André

> 
> 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/
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list