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

Qt-interest Archive, March 2008
Finding start and end visible blocks in QTextEditor


Message 1 in thread

Hi group,
I am trying to boost our text editor highlighter 's performance by just 
highlight the visible part of the text (it's currently really slow for 
big files ).  I spent much time on Qt docs but could not find a way to 
check if a text block is visible or not.
Thanks,

-- 
 [ signature omitted ] 

Message 2 in thread

Tamara Nguyen wrote:
> 
> Hi group,
> I am trying to boost our text editor highlighter 's performance by just 
> highlight the visible part of the text (it's currently really slow for 
> big files ).  I spent much time on Qt docs but could not find a way to 
> check if a text block is visible or not.
> Thanks,
> 

Without knowing the details of your data structures available:

If you are painting the highlight by using QPainter's fillRect(), you 
could trim off highlighted rectangles outside of the paint event by 
testing that the QPaintEvent's rectangle intersects the highlight rectangle.

--
 [ signature omitted ] 

Message 3 in thread


Sorry, I did not give much background info.  I am using 
QSyntaxHighlighter and implemented highlightBlock() virtual function.
The way QSyntaxHighligher works is that it calls hilightBlock() on the 
block that has changes.  When the document is already loaded, it works 
perfectly (it only reformat the changed block.  However, during the 
loading process, it has to reformat the whole document which could be 
huge.  I am trying to find out which part of the document is visible 
(for a particular QTextEdit) and only reformat that part.



Tamara Nguyen
PDF Solutions, Inc.
(408) 283 5655 



Rob Douglas wrote:
> Tamara Nguyen wrote:
>>
>> Hi group,
>> I am trying to boost our text editor highlighter 's performance by 
>> just highlight the visible part of the text (it's currently really 
>> slow for big files ).  I spent much time on Qt docs but could not 
>> find a way to check if a text block is visible or not.
>> Thanks,
>>
>
> Without knowing the details of your data structures available:
>
> If you are painting the highlight by using QPainter's fillRect(), you 
> could trim off highlighted rectangles outside of the paint event by 
> testing that the QPaintEvent's rectangle intersects the highlight 
> rectangle.
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ] 

Message 4 in thread

Tamara Nguyen wrote:
> 
> 
> Sorry, I did not give much background info.  I am using 
> QSyntaxHighlighter and implemented highlightBlock() virtual function.
> The way QSyntaxHighligher works is that it calls hilightBlock() on the 
> block that has changes.  When the document is already loaded, it works 
> perfectly (it only reformat the changed block.  However, during the 
> loading process, it has to reformat the whole document which could be 
> huge.  I am trying to find out which part of the document is visible 
> (for a particular QTextEdit) and only reformat that part.
> 
> 
> 
> Tamara Nguyen
> PDF Solutions, Inc.
> (408) 283 5655
> 
> 
> Rob Douglas wrote:
>> Tamara Nguyen wrote:
>>>
>>> Hi group,
>>> I am trying to boost our text editor highlighter 's performance by 
>>> just highlight the visible part of the text (it's currently really 
>>> slow for big files ).  I spent much time on Qt docs but could not 
>>> find a way to check if a text block is visible or not.
>>> Thanks,
>>>
>>
>> Without knowing the details of your data structures available:
>>
>> If you are painting the highlight by using QPainter's fillRect(), you 
>> could trim off highlighted rectangles outside of the paint event by 
>> testing that the QPaintEvent's rectangle intersects the highlight 
>> rectangle.
>>
>> -- 
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
>> "unsubscribe" in the subject or the body.
>> List archive and information: http://lists.trolltech.com/qt-interest/
>>
>>
> 
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

Though I have not tried this, you may find some use from the QTextCursor 
returned from

QTextCursor QTextEdit::cursorForPosition ( const QPoint & pos ) const

I see from the docs that QTextCursor will give you a QTextBlock. You may 
be able to use that to determine from screen coordinates, whether or not 
a different block is on the screen.

But here I would kick off to someone whose used QSyntaxHighlighter more.

Best Regards!
-Rob

--
 [ signature omitted ]