本页内容

Utils::VariableChooser Class

class Utils::VariableChooser

VariableChooser 类用于在行编辑器、文本编辑器或纯文本编辑器中添加一个用于选择Qt Creator 变量的工具窗口。更多内容...

Header: #include <coreplugin/variablechooser.h>

公共函数

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

详细说明

如果您允许用户将Qt Creator 变量添加到用户界面中指定的字符串中(例如,当用户可以通过文本控件提供字符串时),则应为其添加一个变量选择器。变量选择器允许用户打开一个工具窗口,其中包含所有可用变量的列表及其描述。 双击一个变量会将相应的字符串插入到对应的文本控件中,就像行编辑一样。

带变量选择器的外部工具首选项

变量选择器会监听其父控件所有子控件的焦点变化。当某个文本控件获得焦点时,变量选择器会检查该控件是否启用了变量支持。如果控件支持变量,则在获得焦点期间,其中会显示一个用于打开变量选择器的工具按钮。

支持的文本控件包括:QLineEdit 、QTextEdit 和QPlainTextEdit 。

当其父控件被删除时,变量选择器也将被删除。

示例:

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

成员函数文档

[explicit] VariableChooser::VariableChooser(QWidget *parent = nullptr)

创建一个变量选择器,用于跟踪parent 的所有子节点,以提供变量支持。所有权也会转移至parent 。

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

添加宏展开提供程序provider 。

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

将控件textcontrol 标记为支持变量。

如果控件向宏展开器本身提供了一个变量,请将ownName 设置为该变量名,以防止用户选择该变量,否则会导致无限递归。

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.