Classes | GUI > Views

Button : View : QObject : Object

A multi-state button
Subclasses: QButton


A multi-state button.

Some Important Issues Regarding Button

Failure to set any states at all results in an invisible button.

The button performs its action upon releasing the mouse. In musical contexts, you might want to use mouseDownAction_() to set a function to be performed on pressing the mouse (see View, and examples below).

If the drag contains a number, then valueAction_() is performed using the currentDrag. If the drag contains anything else, action is set to the current drag. You could, for example, drag a function to a Button, and action would then be set to that function.

Class Methods

Button.new(parent, bounds)

From superclass: View



The parent view.


An instance of Rect, or a Point indicating width@height.



Inherited class methods

Undocumented class methods


Instance Methods


.states = stateArray

An array of labels and colors defining the states of the button.



An Array of arrays of the form [ [String, strColor, bgColor] , .... ]


.value = argVal

Sets or returns the index of the current state. This will not evaluate the function assigned to action (see View).



The index of an item in the states array.

.valueAction = anInt

Sets the button to display the item at index anInt of the states array, and evaluates action (see View), if the value has changed.



The index of an item in the states array.


.string = string

Sets or gets the text of the currently active state.


.font = aFont

From superclass: View

Sets the Font of the button. Default value is the default font: Font.default .



An instance of Font.

Subclassing and Internal Methods

The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.


The method called by the primitive upon releasing the mouse.



A key modifier number, which is passed to the action as its second argument upon mouse-releasing the button.

.defaultKeyDownAction(char, modifiers, unicode, keycode, key)

From superclass: View


The default keydown actions are:

" "value + 1space
\rvalue + 1
\nvalue + 1
3.asAsciivalue + 1enter key or cmd-C on macOS

To change these use defaultKeyDownAction_, see View.


From superclass: QObject

A list of properties to which this view responds. See View.


[ \bounds, \visible, \enabled, \canFocus, \resize, \background, \minWidth, \maxWidth, \minHeight, \maxHeight, \value, \font, \states, \focusColor ]


The method called by default when initiating a drag from a Button. Returns the same as -value.


The method called by default when attempting to drop a drag in this object. By default, Button will respond only to drags where the drag contains a Number or Function.


The default method called when a drag has been received. If the drag contains a number, then action is set to the current drag. Otherwise valueAction_() is performed using the currentDrag.

Inherited instance methods

Undocumented instance methods


.action = func

From superclass: View

.icon = image


.iconSize = size


.menu = menu


In a musical context, a button-down press is more meaningful than a button-up (release) as it's more intuitive to press a button on the beat. For that you can use View's View: -mouseDownAction (a superclass of Button).

If you drag a function to a button, the button's action is set to that function. you can us this for swapping functions.

Using Routine to set button states on the fly.

Using Routine to set button states on the fly 2.

Complex drag and drop example try dragging the buttons to white slot, and then between white slots, or simply out of the view.