【发布时间】:2021-09-15 00:31:11
【问题描述】:
我正在使用 C++ 和 Qt6,并且我正在创建一个文本编辑器,该编辑器模仿 Word 或 Evernote 的基本功能,供那些使用它的人使用。 我希望当用户按下键选项卡时发生这种情况:
第二个子弹是我得到的,第三个子弹是我想要的。
我已经准备好了这段代码:
QTextCursor cursor = ui->textEditor->textCursor();
QTextList *currentList = cursor.currentList();
if(currentList)
{
QTextListFormat listFormat;
QTextListFormat::Style currentStyle = currentList->format().style();
listFormat.setIndent(cursor.currentList()->format().indent() + increment);
if (currentStyle == QTextListFormat::ListDisc || currentStyle == QTextListFormat::ListCircle || currentStyle == QTextListFormat::ListSquare)
{
if (listFormat.indent() == 1){listFormat.setStyle(QTextListFormat::ListDisc);}
if (listFormat.indent() == 2){listFormat.setStyle(QTextListFormat::ListCircle);}
if (listFormat.indent() >= 3){listFormat.setStyle(QTextListFormat::ListSquare);}
}
if (currentStyle == QTextListFormat::ListDecimal || currentStyle == QTextListFormat::ListUpperAlpha || currentStyle == QTextListFormat::ListLowerAlpha)
{
if (listFormat.indent() == 1){listFormat.setStyle(QTextListFormat::ListDecimal);}
if (listFormat.indent() == 2){listFormat.setStyle(QTextListFormat::ListUpperAlpha);}
if (listFormat.indent() >= 3){listFormat.setStyle(QTextListFormat::ListLowerAlpha);}
}
currentList->setFormat(listFormat);
}
else
{
QTextBlockFormat blockFormat = cursor.block().blockFormat();
blockFormat.setIndent( increment == 1 ? blockFormat.indent() + 1 : (blockFormat.indent() == 0 ? 0 : blockFormat.indent() - 1));
cursor.setBlockFormat(blockFormat);
}
有没有一种方法可以改变 Tab 键在焦点 QTextEdit 中按下时的作用?
【问题讨论】:
标签: c++ qt qt5 desktop-application qt6