qtextdocument

How do I determine the height of a QTextDocument?

烂漫一生 提交于 2019-12-14 02:08:54
问题 Given a specific width, I want to find out the height of a QTextDocument . In other words, if the QTextEdit that contains the QTextDocument is w wide, what is its minimum height h in order to fully display the document without the need for scrollbars? 回答1: Set the width for the QTextDocument object to your desired with and then call the function size().height(), this should return the height required for the width you have give it before. Have a look at the size() function documentation of

Hiding text with QSyntaxHighlighter

此生再无相见时 提交于 2019-12-14 00:58:10
问题 Problem: I want to implement a text editing widget for text with additional tags. I'd like some tags to be invisible in some cases so that they do not distract the user. Environment: I'm using PyQt and prefer to use QPlainTextWidget and QSyntaxHighlighter . Approach: With QSyntaxHighlighter I can set QTextCharFormat for the strings which match my requirement. QTextCharFormat has gives me all font properties like size, colors, etc. but: I haven't found a option to hide the text or reduce its

Problem in Moving QTextCursor to the End

元气小坏坏 提交于 2019-12-12 14:12:45
问题 I'm trying to implement a simple text search in an editor i'm writing. Everything have been fine until this problem! I'm trying to implement a backward search here. The procedure is: look for the subject backward, if not found, beep once, and if find button was pressed again, go to the end of the document, and do the search again. "reachedEnd" is an int, defined as a private member of the editor class. Here's the function that does the backward search. void TextEditor::findPrevPressed() {

page x of y using QPrinter

谁都会走 提交于 2019-12-10 10:56:48
问题 im generating a pdf file from html code using qt: QTextDocument *document = new QTextDocument(); document->setHtml(htmlContent); QPrinter printer(QPrinter::HighResolution); printer.setPageSize(QPrinter::A4); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("filename.pdf"); document->print(printer); Is it possible to have the page information "Page X of Y" instead of only the page number? If yes, how? 回答1: The solution I propose is based on this code. I have added the

Qt - several QTextBlock inline

谁都会走 提交于 2019-12-07 05:32:06
问题 Is it possible to arrange several QTextBlocks in QTextDocument in one horizontal line? I need to know which block of text was clicked and QTextBlock would be nice to use due to its method setUserState(int), which can be used to hold id of particular block. Are there better approaches? 回答1: Not sure if I got your question right, but I am taking a shot at it (some three years after the question was asked.....) In principle you can put QTextBlocks in a horizontal line using a QTextTable . If you

How to access QTextDocument pages

懵懂的女人 提交于 2019-12-04 16:33:30
I am trying to build an application that would display rich text documents in paginated fashion - more or less like MS Word does. For now, I would like to have only one page displayed at a time. From this question I have learned that I need to represent the document by QTextDocument . While the author of the question focuses more on the view representation, I would like to learn about accessing document data in paginated fashion. I can see that the class has methods such as setPageSize() and pageCount() . Calling setPageSize() seems to update pageCount() accordingly. The problem is I do not

Remove a line/block from QTextEdit

旧时模样 提交于 2019-12-04 03:26:22
问题 I'm struggling with block/line removal from QTextEdit . Code below should(?) work but it ends up in infinite loop for some unknown to me reason. I have a suspicion that next() and previous() are not welcome if QTextDocument is being edited. QTextBlock block = document()->begin(); while (block.isValid()) { if (to_do_or_not_to_do(block)) { QTextCursor cursor(block); cursor.select(QTextCursor::BlockUnderCursor); cursor.removeSelectedText(); } block = block.next(); } Iterating using QTextDocument

Populate a QTextDocument from a .odt file

和自甴很熟 提交于 2019-12-02 02:10:27
I am writing a rich text editor using C++ and Qt. For now, I would like it to support (at least) the .odt format. I found QTextDocumentWriter for writing the contents of the QTextDocument to a file, but I can't seem to find anything to read that back into the QTextDocument, which obviously makes saving it sort of useless in the first place. So the question is, how do I load an .odt document into a QTextDocument? Qt does not currently support the ODT format. Okular has code that does parses ODT to a QTextDocument. Beware: Okular source code is released under GPL license. 来源: https:/

Qt ignores CSS in QTextDocument

旧时模样 提交于 2019-12-01 21:43:37
Here is a small snippet of my code, I don't know why but Qt is ignoring the css. QTextDocument *mTextDocument = new QTextDocument(0); QTextEdit *textEdit = new QTextEdit(0); mTextDocument->setDefaultStyleSheet(QString::fromUtf8("body{background-color: rgb(0,111,200);}")); QTextCursor *_cursor = new QTextCursor(mTextDocument); textEdit->setDocument(mTextDocument); _cursor->insertBlock(); _cursor->insertHtml("<html><body><p>Hello world</p></body></html>"); textEdit->show(); I'm using Qt 4.8. Your document already has html and body tags, so they are simply ignored when they are found in

Remove a line/block from QTextEdit

十年热恋 提交于 2019-12-01 17:49:39
I'm struggling with block/line removal from QTextEdit . Code below should(?) work but it ends up in infinite loop for some unknown to me reason. I have a suspicion that next() and previous() are not welcome if QTextDocument is being edited. QTextBlock block = document()->begin(); while (block.isValid()) { if (to_do_or_not_to_do(block)) { QTextCursor cursor(block); cursor.select(QTextCursor::BlockUnderCursor); cursor.removeSelectedText(); } block = block.next(); } Iterating using QTextDocument::findBlockByNumber() and deleting block in the same way as above didn't worked either. I would