Hey there,
I want to know the number of line my QTextDocument is splitted into, any way to do that ?
I'm not sure "Blocks" are the same thing.
Thanks.
Hey there,
I want to know the number of line my QTextDocument is splitted into, any way to do that ?
I'm not sure "Blocks" are the same thing.
Thanks.
Let me rephrase:
Is there a way to know wether a QTextDocument is taking one line OR broke into several lines ?
... Nobody ?
Here it is:
Qt Code:
int number_of_lines = l.size();To copy to clipboard, switch view to plain text mode
Thanks, but, doesn't work in my case, I need lines not paragraphes and those are not visible characters.
In QTextDocument, the paragraph is the single line (not wrapped). Paragraphs are the lines that internally separated by QChar::ParagraphSeparator instead of \n. So getting the number of paragraphs, you'll get the count of lines.
The another solutions is:
Qt Code:
To copy to clipboard, switch view to plain text mode
1- QTextDocument if its save to html it save it one only 1 line html and 2-3 css line.
2- if you like to split QTextBlock to count and check text ... you can iterate like source from
http://fop-miniscribus.googlecode.co.../qdocxhtml.cpp
http://fop-miniscribus.googlecode.co...se/qdocxhtml.h is a QTextDocument to html without mountains from css chunk...
3- if you like to drawline nr. by editing from viewport have a look on source:
http://fop-miniscribus.googlecode.co...ighlighter.cpp
http://fop-miniscribus.googlecode.co...lhighlighter.h
is a xml text editor widged and display line nr...
if not 1,2,3 please What Is It your target?
I have tried the following code and yours method,but found it was useless,lines was zero. I donot know why?
Qt Code:
int number_of_lines = l.size(); printf("bn:%d,lines:%d\n",textViewer->document ()->blockCount(),number_of_lines);To copy to clipboard, switch view to plain text mode
OK, at least that works:
Qt Code:
int lines_count = textEdit->toPlainText().count("\n");To copy to clipboard, switch view to plain text mode
Hey there,
let me explain what I really want.
- I have a QTextDocument.
- I setHtml with some html content.
- I call QTextDocument::setTextWidth to set the page width.
-> The text is sliced into several lines to fit the Page width.
>> I want to know the NUMBER of those lines.
(not the number of lines in a QString).
Thanks.
what is parent from QTextDocument ?
1- QGraphicsTextItem , 2 - QTextEdit or 3 - QTextBrowser
QTextDocument can only stay on this 3 parent by edit ... i not know other.
Only GraphicsViewEdit ( http://www.qt-apps.org/content/show....?content=80234 ) having other special small Api to handle QTextDocument.
this X parent tell you how may line you having...
and QAbstractTextDocumentLayout tell you all corect rect from each line and size..
search QTextLine on this forum.... and you can grab the exact QTextcursor x,y .
QTextDocument ::setPageSize ( const QSizeF & size ) break line and on draw level
QAbstractTextDocumentLayout is paint the correct size...
I'm sorry but :
- if I setTextWidth on a document.
-> The page size changes BEFORE the paint event.
So the document has been laid out, and the page size calculated.
There should be a WAY of obtaining this line break number.
The problem is the fact that some component are missing in QTextDocument.
QAbstractTextDocumentLayout is friend from QTextDocument and show all info that you need
Bookmarks