I am having similar problems, trying to write a routine to turn a block of text, with multiple lines, into a HTML list:
QString listString
= EDITOR
->textCursor
().
selectedText();
if( !listString.isEmpty() ) {
for( int a = 0; a < stringList.count(); a++ ) {
stringList[a].prepend( "<li>" );
stringList[a].append( "</li>" );
}
listString = stringList.join( "\n" );
listString.prepend( "<ul>" );
listString.append( "</ul" );
EDITOR->insertPlainText( listString );
}
QString listString = EDITOR->textCursor().selectedText();
if( !listString.isEmpty() ) {
QStringList stringList = listString.split( QChar( QChar::LineSeparator ) );
for( int a = 0; a < stringList.count(); a++ ) {
stringList[a].prepend( "<li>" );
stringList[a].append( "</li>" );
}
listString = stringList.join( "\n" );
listString.prepend( "<ul>" );
listString.append( "</ul" );
EDITOR->insertPlainText( listString );
}
To copy to clipboard, switch view to plain text mode
This also didn't work:
QString listString
= EDITOR
->textCursor
().
selectedText();
if( !listString.isEmpty() ) {
listString.prepend( "<ol><li>" );
listString.
replace( QChar( QChar::LineSeparator ),
listString.append( "</li></ol>" );
EDITOR->insertPlainText( listString );
}
QString listString = EDITOR->textCursor().selectedText();
if( !listString.isEmpty() ) {
listString.prepend( "<ol><li>" );
listString.replace( QChar( QChar::LineSeparator ),
QString( "</li>%1<li>" ).arg( QChar( QChar::LineSeparator ) ) );
listString.append( "</li></ol>" );
EDITOR->insertPlainText( listString );
}
To copy to clipboard, switch view to plain text mode
It treats the whole block as a single line, so that the list is opened and closed as expected, but contains only one element, i.e. the whole selection. However, the newlines themselves do appear when the listString is inserted back into the QTextEdit.
Does anyone know the cause of this, and if there is any way round it?
Bookmarks