Qt Creator Manual | Semantic Highlighting

Qt Creator Manual 4.5.2

Working in Edit Mode ◦ Checking Code Syntax

# Semantic Highlighting

Qt Creator understands the C++, QML, and JavaScript languages as code, not as plain text. It reads the source code, analyzes it, and highlights it based on the semantic checks that it does for the following code elements:

- Types (such as classes, structs, and type definitions)
- Local variables
- Class fields
- Virtual functions

To specify the color scheme to use for semantic highlighting, select Tools > Options > Text Editor > Fonts & Color.

Qt Creator supports syntax highlighting also for other types of files than C++, QML, or JavaScript.

## Generic Highlighting

Generic highlighting is based on highlight definition files that are provided by the Kate Editor. You can download highlight definition files for use with Qt Creator. For more information about the definition files, see KDE-Files.org.

If you have a Unix installation that comes with the Kate Editor, you might already have the definition files installed. Typically, the files are located in a read-only directory, and therefore, you cannot manage them. Qt Creator can try to locate them and use them as fallback files, when the primary location does not contain the definition for the current file type. You can also specify the directory that contains preinstalled highlight definition files as the primary location.

When you open a file for editing and the editor cannot find the highlight definition for it, an alert appears. To suppress the alerts, you can specify patterns for ignoring files.

To download highlight definition files:

1. Select Tools > Options > Text Editor > Generic Highlighter.

2. In the Location field, specify the path to the primary location for highlight definition files.
3. Click Download Definitions to open a list of highlight definition files available for download.

4. Select highlight definition files in the list and click Download Selected Definitions.
5. Select the Use fallback location check box to specify the secondary location where the editor will look for highlight definition files.
6. Click Autodetect to allow Qt Creator to look for highlight definition files on your system, or click Browse to locate them in the file system yourself.
7. In the Ignored file patterns field, specify file patterns to suppress alerts if the highlight definitions for the specified files are not found.
8. Click OK to save your changes.

## Highlighting and Folding Blocks

Use block highlighting to visually separate parts of the code that belong together. For example, when you place the cursor within the braces, the code enclosed in braces is highlighted.

To enable block highlighting, select Tools > Options > Text Editor > Display > Highlight blocks.

Use the folding markers to collapse and expand blocks of code within braces. Click the folding marker to collapse or expand a block. In the figure above, the folding markers are located between the line number and the text pane.

To show the folding markers, select Tools > Options > Text Editor > Display > Display folding markers. This option is enabled by default.

When the cursor is on a brace, the matching brace is animated by default. To turn off the animation and just highlight the block and the braces, select Tools > Options > Text Editor > Display and deselect Animate matching parentheses.

You can use keyboard shortcuts to move within and between blocks. To go to block end, press Ctrl+] and to go to block start, press Ctrl+[. To also select the lines from the cursor position to the end or beginning of the block, press Ctrl+Shift+] and Ctrl+Shift+[, respectively.

To select the current block, press Ctrl+U. A second key press extends the selection to the parent block. To undo the last selection, press Ctrl+Alt+Shift+U. To enable smart block selection, select Tools > Options > Text Editor > Behavior > Enable smart selection changing.

Working in Edit Mode ◦ Checking Code Syntax