PDA

View Full Version : QTextBlock::setVisible(false) has no effect [unresolved]



JohannesMunk
13th December 2009, 14:51
I still couldn't figure this one out:



QTextEdit* te = new QTextEdit();
..
QTextBlock (http://doc.trolltech.com/latest/QTextBlock.html) blk = te->document()->begin();
while (blk.isValid())
{
bool cond = false;
if (blk.contains(".."))
cond = true;
blk.setVisible(cond);
blk = blk.next();
}Why doesn't QTextBlock::setVisible work? Am I doing something wrong or is the feature just not implemented yet?

http://www.qtcentre.org/forum/f-qt-programming-2/t-qtextblocksetvisible-21939.html

Thx in advance!

Johannes

fullmetalcoder
13th December 2009, 15:00
have you tried explicitly triggering a relayout (e.g calling QTextDocument::markContentsDirty() (http://doc.trolltech.com/latest/qtextdocument.html#markContentsDirty) )?

JohannesMunk
13th December 2009, 15:19
Hi!

Thanks for your quick reply!



#include <QtGui/QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTextEdit* te = new QTextEdit();
te->setPlainText("Great [Debug]\nThis is an Error![Error]\nGreat [Debug]\n");

QTextBlock blk = te->document()->firstBlock();
while (blk.isValid())
{
bool cond = true;
if (blk.text().contains("Debug"))
{
cond = false;
qDebug() << "Setting block invisible";
}
blk.setVisible(cond);
blk = blk.next();
}

te->document()->markContentsDirty(0,te->document()->end().position());

te->show();
return a.exec();
}
The documentation doesn't state what the markContentsDirty parameters are expressed in.. document.position or blockindices? I guessed document position. Is that right?

However, like this it still doesn't work!

Any further ideas?

Johannes

cyberpro4
19th February 2010, 12:47
Hi!
Have you tried to show() the QTextEdit BEFORE the setVisible() on his QTextBlock?

JohannesMunk
19th February 2010, 12:56
Hi! Thanks for your reply!

I'm using this code actually to implement a filter, if a block contains a certain word. As the user configures the filter, the QTextEdit is visible way before. Only in this small example its the other way around.

Any further ideas?

Johannes

cyberpro4
19th February 2010, 14:56
Ok, this is a small piece of code to "Fold" a certain piece of document in my Code editor.
As you can see I call a setVisible( false ) to the QTextBlock.


void CCodeEditor_FoldArea::mouseReleaseEvent(QMouseEven t * eve){
QTextBlock thblock = editor->cursorForPosition( eve->pos() ).block().next();

while( thblock.isValid() && !thblock.isVisible() ){
thblock.setVisible( true );
thblock = thblock.next();
}

if( dynamic_cast<CMagnum_TextBlock*>(thblock.userData()) != 0 ){
CMagnum_TextBlock* mudata = dynamic_cast<CMagnum_TextBlock*>(thblock.userData());

while( thblock.isValid() && thblock.blockNumber() < mudata->foldable() && mudata->foldable() != -1 ){
thblock.setVisible( false );
thblock = thblock.next();
}
}

editor->viewport()->update();
editor->lineNumberArea->update();
editor->m_foldArea->update();
}

... at the end I have added editor->viewport->update().
Keep in mind that "editor" is a QPlainTextEdit and viewport() return his QAbstractScrollArea.
Maybe an update can help you :)

JohannesMunk
19th February 2010, 15:58
Aah! With QPlainTextEdit it works! No update required. Doesn't matter where show is called.

Is block.setVisible(false) supposed to not work with QTextEdit?


#include <QtGui/QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QPlainTextEdit* te = new QPlainTextEdit();
te->setPlainText("Great [Debug]\nThis is an Error![Error]\nGreat [Debug]\n");

QTextBlock blk = te->document()->firstBlock();
while (blk.isValid())
{
bool cond = true;
if (blk.text().contains("Debug"))
{
cond = false;
qDebug() << "Setting block invisible";
}
blk.setVisible(cond);
blk = blk.next();
}

te->show();
//te->document()->markContentsDirty(0,te->document()->end().position());
//te->viewport()->update();

return a.exec();
}


Thx for your time!

Johannes

cyberpro4
19th February 2010, 16:16
Happy to be useful :)
But i'll advise you, In my code editor i have a strange error with setVisibile():when i hide a lot of block, seem that the Vertical scroolbar "scroll" the hide blocks too! :confused:
If you find a solution please keep me updated! :)

Thx
Claudio