Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draggable NSButton

Is there any way of making an NSButton draggable? I mean like in the final built application, the user can drag the NSButton.

I'm trying to do something almost "Dashboard" style... like draggable things. At the moment, I'm just using NSButtons that stay in place, but it'd be nice if they could be dragged around.

like image 776
Seb Jachec Avatar asked Apr 09 '26 00:04

Seb Jachec


1 Answers

NSButton normally eats up all mouse events. Therefore you must subclass NSButton and override not only the dragging handling but also the click handling:

- (void)mouseDown:(NSEvent *)theEvent
{
    [self highlight:YES];
}

- (void)mouseDragged:(NSEvent *)event
{
// start a dragging session
}

- (void)mouseUp:(NSEvent *)theEvent
{
    [self performClick:self];
}
like image 170
Frank Hintsch Avatar answered Apr 10 '26 21:04

Frank Hintsch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!