Extending Qt Creator Manual | VariableChooser

Extending Qt Creator Manual 4.3.0

# VariableChooser Class

(Core::VariableChooser)

The VariableChooser class is used to add a tool window for selecting Qt Creator variables to line edits, text edits or plain text edits. More...

Header: | #include <VariableChooser>

- List of all members, including inherited members

## Public Functions

| VariableChooser(QWidget *parent = 0)
void | addMacroExpanderProvider(const Utils::MacroExpanderProvider &provider)
void | addSupportedWidget(QWidget *textcontrol, const QByteArray &ownName = QByteArray())

## Static Public Members

void | addSupportForChildWidgets(QWidget *parent, Utils::MacroExpander *expander)

## Detailed Description

The VariableChooser class is used to add a tool window for selecting Qt Creator variables to line edits, text edits or plain text edits.

If you allow users to add Qt Creator variables to strings that are specified in your UI, for example when users can provide a string through a text control, you should add a variable chooser to it. The variable chooser allows users to open a tool window that contains the list of all available variables together with a description. Double-clicking a variable inserts the corresponding string into the corresponding text control like a line edit.

The variable chooser monitors focus changes of all children of its parent widget. When a text control gets focus, the variable chooser checks if it has variable support set, either through the addVariableSupport() function. If the control supports variables, a tool button which opens the variable chooser is shown in it while it has focus.

Supported text controls are QLineEdit, QTextEdit and QPlainTextEdit.

The variable chooser is deleted when its parent widget is deleted.

Example:

      QWidget *myOptionsContainerWidget = new QWidget;
      new Core::VariableChooser(myOptionsContainerWidget)
      QLineEdit *myLineEditOption = new QLineEdit(myOptionsContainerWidget);
      myOptionsContainerWidget->layout()->addWidget(myLineEditOption);
      Core::VariableChooser::addVariableSupport(myLineEditOption);

## Member Function Documentation

### VariableChooser::VariableChooser(QWidget *parent = 0)

Creates a variable chooser that tracks all children of parent for variable support. Ownership is also transferred to parent.

See also addVariableSupport().

### void VariableChooser::addMacroExpanderProvider(const Utils::MacroExpanderProvider &provider)

### `[static]` void VariableChooser::addSupportForChildWidgets(QWidget *parent, Utils::MacroExpander *expander)

### void VariableChooser::addSupportedWidget(QWidget *textcontrol, const QByteArray &ownName = QByteArray())

Marks the control as supporting variables.

See also kVariableSupportProperty.