Adding QtCollider widgets¶
These instructions detail how to add functionality to existing QtCollider widgets (such as TreeView and Knob). Each widget typically corresponds to a single Qt class, and the simplest way to add functionality is by providing access to an existing C++ function of the Qt widget.
Locate the C++ source for the widget in
/QtCollider/widgets/
.Add the signature for the function in the header file.
Add the implementation for the function in the implementation file.
Locate the SC source for the widget in
/SCClassLibrary/Common/GUI/Base/
.Add a suitably named new method in the class file that calls down to the QtCollider widget using
invokeMethod
.Document the method in the corresponding schelp file in
/HelpSource/Classes/
.
Technical note: not all types can be transcoded between SuperCollider and QtCollider widgets. However, all primitive
types, some collection types, and a few class types are supported. The code which controls this can be found in
QtCollider::MetaType::find( PyrSlot * )
.
Example¶
PR #3560 demonstrates how to do this by adding
setColumnWidth
to TreeView
:
The C++ files are
/QtCollider/widgets/QcTreeWidget.{cpp,h}
The function signature is:
Q_INVOKABLE void setColumnWidth( int column, int width );
The implementation simply calls up to
QTreeView
:void QcTreeWidget::setColumnWidth( int column, int width ) { QTreeWidget::setColumnWidth( column, width ); }
The SC file is
/SCClassLibrary/Common/GUI/Base/QTreeView.sc
The new method simply forwards arguments to
invokeMethod
:setColumnWidth { arg column, width; this.invokeMethod( \setColumnWidth, [column, width] ) }
The documentation is added to
/HelpSource/Classes/TreeView.schelp
:METHOD:: setColumnWidth ARGUMENT:: column The integer index of the column to modify ARGUMENT:: width Integer width in pixels