Results 1 to 8 of 8

Thread: QTextBlock::setVisible(false) has no effect [unresolved]

  1. #1
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextBlock::setVisible(false) has no effect [unresolved]

    I still couldn't figure this one out:

    Qt Code:
    1. QTextEdit* te = new QTextEdit();
    2. ..
    3. [URL="http://doc.trolltech.com/latest/QTextBlock.html"]QTextBlock[/URL] blk = te->document()->begin();
    4. while (blk.isValid())
    5. {
    6. bool cond = false;
    7. if (blk.contains(".."))
    8. cond = true;
    9. blk.setVisible(cond);
    10. blk = blk.next();
    11. }
    To copy to clipboard, switch view to plain text mode 
    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-p...ble-21939.html

    Thx in advance!

    Johannes
    Last edited by JohannesMunk; 13th December 2009 at 16:52.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect

    have you tried explicitly triggering a relayout (e.g calling QTextDocument::markContentsDirty() )?
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect

    Hi!

    Thanks for your quick reply!

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QTextEdit* te = new QTextEdit();
    9. te->setPlainText("Great [Debug]\nThis is an Error![Error]\nGreat [Debug]\n");
    10.  
    11. QTextBlock blk = te->document()->firstBlock();
    12. while (blk.isValid())
    13. {
    14. bool cond = true;
    15. if (blk.text().contains("Debug"))
    16. {
    17. cond = false;
    18. qDebug() << "Setting block invisible";
    19. }
    20. blk.setVisible(cond);
    21. blk = blk.next();
    22. }
    23.  
    24. te->document()->markContentsDirty(0,te->document()->end().position());
    25.  
    26. te->show();
    27. return a.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    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

  4. #4
    Join Date
    Feb 2010
    Location
    Taranto, Italy
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect [unresolved]

    Hi!
    Have you tried to show() the QTextEdit BEFORE the setVisible() on his QTextBlock?

  5. #5
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect [unresolved]

    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

  6. #6
    Join Date
    Feb 2010
    Location
    Taranto, Italy
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect [unresolved]

    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.

    Qt Code:
    1. void CCodeEditor_FoldArea::mouseReleaseEvent(QMouseEvent * eve){
    2. QTextBlock thblock = editor->cursorForPosition( eve->pos() ).block().next();
    3.  
    4. while( thblock.isValid() && !thblock.isVisible() ){
    5. thblock.setVisible( true );
    6. thblock = thblock.next();
    7. }
    8.  
    9. if( dynamic_cast<CMagnum_TextBlock*>(thblock.userData()) != 0 ){
    10. CMagnum_TextBlock* mudata = dynamic_cast<CMagnum_TextBlock*>(thblock.userData());
    11.  
    12. while( thblock.isValid() && thblock.blockNumber() < mudata->foldable() && mudata->foldable() != -1 ){
    13. thblock.setVisible( false );
    14. thblock = thblock.next();
    15. }
    16. }
    17.  
    18. editor->viewport()->update();
    19. editor->lineNumberArea->update();
    20. editor->m_foldArea->update();
    21. }
    To copy to clipboard, switch view to plain text mode 

    ... 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

  7. The following user says thank you to cyberpro4 for this useful post:

    JohannesMunk (19th February 2010)

  8. #7
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect [unresolved]

    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?

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QPlainTextEdit* te = new QPlainTextEdit();
    9. te->setPlainText("Great [Debug]\nThis is an Error![Error]\nGreat [Debug]\n");
    10.  
    11. QTextBlock blk = te->document()->firstBlock();
    12. while (blk.isValid())
    13. {
    14. bool cond = true;
    15. if (blk.text().contains("Debug"))
    16. {
    17. cond = false;
    18. qDebug() << "Setting block invisible";
    19. }
    20. blk.setVisible(cond);
    21. blk = blk.next();
    22. }
    23.  
    24. te->show();
    25. //te->document()->markContentsDirty(0,te->document()->end().position());
    26. //te->viewport()->update();
    27.  
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Thx for your time!

    Johannes

  9. #8
    Join Date
    Feb 2010
    Location
    Taranto, Italy
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextBlock::setVisible(false) has no effect [unresolved]

    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!
    If you find a solution please keep me updated!

    Thx
    Claudio

Similar Threads

  1. Water waves effect at mouse passage
    By QAlex in forum Qt Programming
    Replies: 0
    Last Post: 24th November 2009, 08:46
  2. Replies: 2
    Last Post: 11th November 2009, 08:03
  3. Zooming effect by scaling widgets
    By Cruz in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2009, 09:43
  4. QPushButton fade effect without animation
    By Kostanev in forum Qt Programming
    Replies: 11
    Last Post: 12th November 2008, 09:46
  5. Designing a "slide-out" effect
    By Gray in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2007, 10:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.