tags:

views:

126

answers:

1

Hi everyone,

i tried to hide textblock's in QTextEdit, but it doesn't work:

block = textedit.document().begin()
block.setVisible(False)

This code works fine for QPlainTextEdit, but not for QTextEdit. In documentation i haven't found any mention of how it should work for QTextEdit, just following:

void QTextBlock::setVisible ( bool visible ) Sets the block's visibility to visible.

This function was introduced in Qt 4.4.

See also isVisible().

How can i hide block's in QTextEdit?

Thank you in advance

+1  A: 

I've confirmed the behavior your describe. In addition, I've confirmed that, in the code you've given, following the setVisible method the block's visibility is indeed False.

So, the clearest explanation I see is this: QPlainTextEdit does not inherit from QTextEdit. They both inherit from QScrollableArea and I can only assume that QTextEdit does not respect the visibility of its document's blocks. The documents used by QPlainTextEdit use QPlainTextLayout objects, and QTextEdit has something else that I cannot determine.

So... I'm not sure it can be done in the way you are intending. One alternative is to filter the text before it gets into the QTextEdit, and Python is well-suited for that task.

self.paragraphs = ["First paragraph","Second Paragraph","Third Paragraph",]
self.display_text = '\n'.join(self.paragraphs[1:])
self.textedit.setText(self.display_text)
stw_dev