Results 1 to 7 of 7

Thread: PyQt4 - QPlainTextEdit: performance when hidding blocks

  1. #1
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default PyQt4 - QPlainTextEdit: performance when hidding blocks

    Morning,
    I am making a little text editor in python. As many others have probably done before, I am trying to implement some folding functionality in it.

    For each block I want to hide I execute:
    _block.setVisible(False)
    Afterwards I execute:
    self.viewport().update()
    I have problems when hiding everything but the first line. The loop hiding more than 80000 plus updating the viewport takes less than second which is perfectly acceptable. But afterthat, the application gets stuck for about 6 minutes showing the message "Not Responding". I cannot interact with application. After that, the result is as expected, with no error messages. And everything works great.

    Any suggestion about what I could do to improve this performance?
    Might it be a bug?

    Kind regards,
    José M.

  2. #2
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    One more thing, after that first execution, next executions take less than second which is exactly what I would expect, from the very beginning.

    Cheers,
    JM

  3. #3
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    I have made an experiment with a small file. The problem seem to happen whenever I fold or unfold and the text is bigger than QPlainTextEdit. Any clue about where should I look at?

    Cheers,
    JM

  4. #4
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    I keep on trying to spot the problem. I have created my own class by mean of:
    Qt Code:
    1. class TextEditor(QtGui.QPlainTextEdit):
    To copy to clipboard, switch view to plain text mode 
    and I have implemented my own event function which captures key presses:
    Qt Code:
    1. def event(self, event):
    2. if event.type() == QtCore.QEvent.KeyPress:
    3. if event.key()==QtCore.Qt.Key_Tab:
    4. self.key_tab_pressed.emit()
    5. return True
    6. .....
    To copy to clipboard, switch view to plain text mode 
    When I hide most of the text (>80000 blocks) the profiler shows that the event function is called >81000 times taking 0.7sg per call. The cumulative time is about 340sg.

    Is there any way to avoid this events to be produced?

    Regards,
    José M.

  5. #5
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    Crappy workaround:

    It looks like changing the visibility creates events. (I don't have a good understanding of this area). So changing the visilibility of >80000 blocks creates >80000events calls. The workaround is I get the document, I assign an empty document to QPlainTextEdit, afterwards I setVisible(False) to the former document and assign again the document to QPlainTextEdit:
    Qt Code:
    1. _document = self.document()
    2. self.setDocument(QtGui.QTextDocument())
    3. for _i in xrange(0,80000):
    4. .... setVisible(False)....
    5. self.setDocument(_document)
    To copy to clipboard, switch view to plain text mode 

    There has to be a far more elegant solution to this.

    Kind regards,
    José M.

  6. #6
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    have you tried .hide() instead of .setVisible(False) ?

  7. #7
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: PyQt4 - QPlainTextEdit: performance when hidding blocks

    Hi prof.ebral,
    QTextBlock doesn't have member: hide.

    Thanks anyway,
    José M.

Similar Threads

  1. QDir::NoDotAndDotDot hidding all files?
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2009, 03:12
  2. Code Blocks
    By upton15 in forum Newbie
    Replies: 1
    Last Post: 17th December 2007, 08:13
  3. QThread blocks gui
    By skoegl in forum Newbie
    Replies: 6
    Last Post: 29th October 2007, 12:09
  4. How to fill the blocks of the Grid one by one?
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 6th June 2007, 12:20
  5. QTableWidget : hidding a column ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 2nd April 2007, 14:35

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.