Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, July 2007
How to remove a text block from QTextEdit (Qt4)


Message 1 in thread

Hi,

The subject says it all. I would like to remove e.g. the first text
block in my QTextEdit widget. Any hint where to look?


Oliver

--
 [ signature omitted ] 

Message 2 in thread

> The subject says it all. I would like to remove e.g. the first text
> block in my QTextEdit widget. Any hint where to look?

You could select it with your QTextCursor and use "
QTextCursor::removeSelectedText ()" to remove the block.

Regards,
Malte

--
 [ signature omitted ] 

Message 3 in thread

Malte Witt wrote:
>> The subject says it all. I would like to remove e.g. the first text
>> block in my QTextEdit widget. Any hint where to look?
> 
> You could select it with your QTextCursor and use "
> QTextCursor::removeSelectedText ()" to remove the block.
> 

Not quite, I tried this:

    QTextDocument * doc = document();
    QTextCursor cursor(doc->begin());
    cursor.select(QTextCursor::BlockUnderCursor);
    qDebug() << cursor.hasSelection() << cursor.selectedText();
    cursor.removeSelectedText();

This will remove the text of the first block, but not the block itself.
Thus a second call will work on the empty block again.


Oliver

--
 [ signature omitted ]