如何用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