TextView:
Filter:
Classes | GUI > Views

TextView : QAbstractScroll : AbstractScroll : View : QObject : Object

A view displaying editable formatted text
Source: QTextView.sc
Subclasses: QTextView

Description

TextView consists of an area where multi-line text can be typed in and edited.

Using the view's methods, the text can be formatted: different font and text color can be applied to parts of the text. Text can also be inserted, removed, and selected programmatically.

The view can open text documents and load from them both plain text, as well as formatted text in HTML, although it can not save the text back to files. However, you can get the contents of the view using the -string method and then implement saving on your own, but the -string method will only return plain text, regardless of how the contents of the view are formatted.

Class Methods

Inherited class methods

Undocumented class methods

TextView.qtClass

Instance Methods

Text and Formatting

.open(path)

Opens a file at path and loads text from it.

The file can be in plain text or HTML (or RTF, in Cocoa GUI) format. Note however that saving formatted text in the view is not supported.

If loading the text from the file succeeds, it will replace any current contents of the view.

Arguments:

path

A String.

.string

.string = string

The entire displayed contents of the view, as plain text.

Setting this variable will replace any current contents of the view.

Arguments:

string

A String.

.setString(string, start, size)

Inserts the string at start position, replacing size amount of following characters. If size is 0, the text will be inserted without any characters being removed.

Arguments:

string

A String - the text to insert.

start

An Integer position within the text, in characters.

size

An Integer amount of characters to be replaced.

.currentLine

The plain text of the line at text cursor.

Formatting

TextView supports text font and color, and can syntax colorize sclang code.

NOTE: The formatting is reset when the string changes.

.setFont(font, start, size)

Applies the font to size amount of characters following the start position.

Arguments:

font

A Font to apply to the desired range of text.

start

An Integer position within the text, in characters.

size

An Integer amount of characters.

.setStringColor(color, start, size)

Applies the color to size amount of characters following the start position.

Arguments:

color

A Color to apply to the desired range of text.

start

An Integer position within the text, in characters.

size

An Integer amount of characters.

.syntaxColorize

Applies colors to text throughout the entire contents of the view, according to the SuperCollider language syntax highlighting scheme.

Text Selection

.selectedString

.selectedString = string

The plain text contained in the current selection.

When getting this variable and there is no selection, the entire line at text cursor is returned (equivalent to -currentLine).

Setting this variable will replace text in the selection with the argument, or do nothing if there is no selection.

Arguments:

string

A String.

Returns:

A String.

.selectionStart

The starting position of the selection. If no text is selected this variable represents the cursor position.

Returns:

An Integer position within the text, in characters.

.selectionSize

The size of the current selection.

Returns:

An Integer amount of characters - 0 if no text is selected.

.select(start, size)

NOTE: Not available in Cocoa GUI.

Selects size amount of characters following the start position. The cursor will remain at the end of the new selection.

Arguments:

start

An Integer position within the text, in characters.

size

An Integer amount of characters.

Appearance

.font

.font = argFont

From superclass: View

The default font of the entire text. This font applies to any text to which a font has not been applied using -setFont.

Arguments:

argFont

A Font.

.stringColor

.stringColor = color

The default color of the entire text. This color applies to any text to which a color has not been applied using -setStringColor.

NOTE: Calling stringColor_ does not affect the cursor's color. Setting a dark background, using background_, and a light text color will leave the cursor as a dark color. It is recommended to set the background and string colors by setting the TextView's palette to an instance of QPalette.

.tabWidth

.tabWidth = pixels

The width of tab characters as they are displayed.

Interaction

.editable

.editable = bool

Whether the contents of the view are editable, i.e. the text can be typed in and deleted by the user.

Arguments:

bool

A Boolean.

.enterInterpretsSelection

.enterInterpretsSelection = bool

Whether the selection will be interpreted and invoked as SuperCollider code when Ctrl/Cmd/Shift + Enter key combination is pressed.

Defaults to false.

Arguments:

bool

A Boolean.

.usesTabToFocusNextView = bool

Whether the tab key will - instead of inserting a tab character into the text - switch focus to the next view (as usual for other views).

Defaults to false.

Arguments:

bool

A Boolean.

.hasHorizontalScroller

.hasHorizontalScroller = aBool

From superclass: AbstractScroll

Whether the horizontal scroller is shown.

Note that if -autohidesScrollers is true the scroller may be hidden despite this variable being set to true. Since the TextView typically wraps text into the next line when a line reaches the edge of the view, the horizontal scroller may never be shown, unless -autohidesScrollers is false.

Defaults to true.

Arguments:

aBool

A Boolean.

.hasVerticalScroller

.hasVerticalScroller = aBool

From superclass: AbstractScroll

Whether the vertical scroller is shown.

Note that if -autohidesScrollers is true the scroller may be hidden despite this variable being set to true.

Defaults to true.

Arguments:

aBool

A Boolean.

.autohidesScrollers

.autohidesScrollers = aBool

From superclass: AbstractScroll

Whether each of the scrollers will be automatically hidden if there is no use for it, i.e. the content is not scrollable in the direction of the scroller.

If -hasHorizontalScroller or -hasVerticalScroller is false, the respective scroller will always be hidden, regardless of this variable.

Defaults to true.

Arguments:

aBool

A Boolean.

Drag and Drop

NOTE: Default drag-and-drop behavior of TextView is not defined in standard SC methods, but in the view implementation instead (except for -defaultGetDrag). It may or may not be overridable by adding your own handlers (see View: Drag and drop), depending on the GUI kit in use.

Dragging from TextView will give the selected text in a String as drag data, while dropping will accept any object and insert it as String at the drop location.

You can also drag files from outside SuperCollider onto a TextView, and it will insert their URLs at the drop location.

.defaultGetDrag

Returns:

Inherited instance methods

Undocumented instance methods

.background

.background = color

Examples