How to resize tabs in QML TextEdit?

I am using the component TextEditfor code editor in my Qt 5.5 application. When you click Tabor paste fragments from other editors, the default bookmark size is applied (which is huge), and I just can not find a way to change this value.

My workaround is to forward key events to a C ++ controller, where I do things like inserting myCustomTabSizetimes spaceCharacterfor each event Qt::Key_Tab. Or manually prepare lines from the clipboard before pasting them.

The class QTextEditprovides a method setTabStopWidth. Is there a QML equivalent for this?

+4
source share
1 answer

QML TextEdit, :

1) objectName TextEdit.

TextEdit {
    objectName: "myTextEdit"
}

2) TextEdit ++.

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

QObject *root = engine.rootObjects().at(0);
QObject *textEdit = root->findChild<QObject*>(QStringLiteral("myTextEdit"));

3) QTextDocument, TextEdit.

QQuickTextDocument *quickTextDocument = textEdit->property("textDocument").value<QQuickTextDocument*>();
QTextDocument *document = quickTextDocument->textDocument();

4) QTextOption.

QTextOption textOptions = document->defaultTextOption();

5)

textOptions.setTabStop(10);

6) .

document->setDefaultTextOption(textOptions);
+5

Source: https://habr.com/ru/post/1610652/


All Articles