如何用Qt通过单击按钮在QTextEdit中创建项目符号或编号列表?此外,有必要列出通过单击相同按钮选择的列表。当光标在列表中并且您单击该按钮时,列表项目将变为非列表项目,而是一个简单的段落。用两个字我想为我的文本编辑器2按钮创建,其工作方式与(引导和编号按钮是MS Word)相同。如何用Qt创建项目符号或编号列表?
0
A
回答
1
我已经使用这个代码:
void TextEdit::textStyle(int styleIndex)
{
QTextCursor cursor = textEdit->textCursor();
if (styleIndex != 0) {
QTextListFormat::Style style = QTextListFormat::ListDisc;
switch (styleIndex) {
default:
case 1:
style = QTextListFormat::ListDisc;
break;
case 2:
style = QTextListFormat::ListCircle;
break;
case 3:
style = QTextListFormat::ListSquare;
break;
case 4:
style = QTextListFormat::ListDecimal;
break;
case 5:
style = QTextListFormat::ListLowerAlpha;
break;
case 6:
style = QTextListFormat::ListUpperAlpha;
break;
case 7:
style = QTextListFormat::ListLowerRoman;
break;
case 8:
style = QTextListFormat::ListUpperRoman;
break;
}
cursor.beginEditBlock();
QTextBlockFormat blockFmt = cursor.blockFormat();
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
} else {
listFmt.setIndent(blockFmt.indent() + 1);
blockFmt.setIndent(0);
cursor.setBlockFormat(blockFmt);
}
listFmt.setStyle(style);
cursor.createList(listFmt);
cursor.endEditBlock();
} else {
// ####
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
}
从这个
source
。只有
我已经改变
} else {
// ####
QTextBlockFormat bfmt;
bfmt.setObjectIndex(-1);
cursor.mergeBlockFormat(bfmt);
}
下面的代码:
} else {
// ####
QTextBlockFormat bfmt;
bfmt.setObjectIndex(0);
cursor.mergeBlockFormat(bfmt);
setTextCursor(cursor);
}
4
的QTextEdit应该支持HTML文本格式,以便下面的按钮单击处理程序应插入2所列出到文本编辑器:
void MainWindow::on_pushButton_clicked()
{
// will insert a bulleted list
ui->textEdit->insertHtml("<ul><li>text 1</li><li>text 2</li><li>text 3</li></ul> <br />");
// will insert a numbered list
ui->textEdit->insertHtml("<ol><li>text 1</li><li>text 2</li><li>text 3</li></ol>");
}
或者你可以操纵使用QTextDocument和QTextCursor成员文字编辑的内容。下面是一个例子:
void MainWindow::on_pushButton_2_clicked()
{
QTextDocument* document = ui->textEdit->document();
QTextCursor* cursor = new QTextCursor(document);
QTextListFormat listFormat;
listFormat.setStyle(QTextListFormat::ListDecimal);
cursor->insertList(listFormat);
cursor->insertText("one");
cursor->insertText("\ntwo");
cursor->insertText("\nthree");
}
也此链接:Rich Text Processing可能会有所帮助
希望这会有所帮助,至于
相关问题
- 1. 创建两列项目符号列表
- 2. 如何组符号或编号列表到#符号
- 3. 如何创建&raquo项目符号?
- 4. open office java uno API如何创建项目符号列表
- 5. 如何在WordML中创建项目符号列表?
- 6. 如何创建一个嵌套的项目符号列表
- 7. 如何在表格单元格条目或换行符中添加编号或项目符号列表
- 8. 如何删除列表项目符号?
- 9. iphone项目符号列表
- 10. 使用Impress.js创建动画项目符号列表
- 11. 如何创建符号表?
- 12. 如何创建一个加号符号栏按钮项目
- 13. 项目符号从项目符号列表中消失
- 14. 如何查找项目符号列表和格式项目符号(VBA _ Word Documnet)
- 15. asp.net项目符号列表控制 - 如何隐藏项目符号点?
- 16. 如何在node.js中使用pdfkit使用项目符号列表创建文本?
- 17. 从计划中编号和编号或列表和编号构建列表
- 18. 未编号列表项目符号点不集中
- 19. 在Sharepoint列表中创建项目时显示自动编号
- 20. 如何确定org.apache.poi.hwpf.model.ListData的实例属于编号列表或项目符号列表?
- 21. 在PowerPoint 2007中创建嵌套的项目符号列表
- 22. 在HTML中创建项目符号列表
- 23. 从JSON数据创建HTML项目符号列表的问题
- 24. 更改列表项目项目符号/悬停时的编号颜色
- 25. 如何在Textmate中创建自定义符号列表项?
- 26. 如何在记事本++中使用项目符号和编号?
- 27. 如何按项目编号项目编号
- 28. 列中的HTML项目符号列表
- 29. 如何知道列表视图中的项目是否被按下/创建列表视图项目编号
- 30. Apache poi项目符号和编号
第二个变量是我想要的,但是是的incompleate。困难的部分是编写已编写的文本/编号。并且bulleted /编号的文本使unbulleted/unnumbered。实际上,它应该使用相同的可检查按钮或在菜单中进行操作。 – Narek 2010-09-06 17:23:47