PDA

View Full Version : Addin list to QTextEdit



GrahamLabdon
17th January 2012, 10:41
Hi
I am trying to add a numeric list to a QTextEdit.
So I have a QDialog with a QTextEdit and a button which when pressed should add an item to the list.
This is my code so far (for when the button is pressed)

QTextCursor cursor = ui->textEdit->textCursor();
QTextBlockFormat listBlockFormat;
QTextCharFormat listCharFormat;
QString listItemText = "The item";
QTextListFormat listFormat;
listFormat.setIndent(1);
listFormat.setStyle(QTextListFormat::ListDecimal);
cursor.insertBlock();
cursor.beginEditBlock();
cursor.setBlockFormat(listBlockFormat);
cursor.setCharFormat(listCharFormat);
cursor.insertText(listItemText);
QTextList *textList = cursor.createList(listFormat);
textList->add(cursor.block());
cursor.endEditBlock();

This adds list items but they always have the decimal value of 1 –
1. The Item

I know this is because I create a new list every time, but cannot see how to make this work

Any suggestions would be welcome
Thanks

Graham