How to use both the properties of Qtextdocument
-
@ManiRon said in How to use both the properties of Qtextdocument:
@VRonin I tried to do this.
QTextCursor document1; document1.document()->setHtml(hex); QString data = ui->teData->toPlainText(); document1.document()->setPlainText(data);
but i got the above error when i ran with the debug mode . and the error was thrown from document1.document()->setHtml(hex); this line of code .
-
hex
is doubtless some illegal HTML (not HTML at all). -
You persist in trying to use
document()->setHtml(...)
followed bydocument()->setPlainText(data)
. If you do not believe me that you cannot use both (the second will simply replace the first), why don't you read the docs or try a small test for yourself so that you know why it won't work?
-
-
@ManiRon said in How to use both the properties of Qtextdocument:
@VRonin I tried to do this.
QTextCursor document1; document1.document()->setHtml(hex); QString data = ui->teData->toPlainText(); document1.document()->setPlainText(data);
but i got the above error when i ran with the debug mode . and the error was thrown from document1.document()->setHtml(hex); this line of code .
-
hex
is doubtless some illegal HTML (not HTML at all). -
You persist in trying to use
document()->setHtml(...)
followed bydocument()->setPlainText(data)
. If you do not believe me that you cannot use both (the second will simply replace the first), why don't you read the docs or try a small test for yourself so that you know why it won't work?
-
-
@JonB header has top left corner one image and top right corner one image and a title at the middle of the two images, and after that i want insert my texts. This much things i want to do . Is there any way ? :(
-
@ManiRon Take a look at my code above. Look at what I pass in the constructor of QTextCursor and look what methods I'm calling. now look at your code and notice the differences
-
@ManiRon said in How to use both the properties of Qtextdocument:
@VRonin I tried to do this.
QTextCursor document1; document1.document()->setHtml(hex); QString data = ui->teData->toPlainText(); document1.document()->setPlainText(data);
but i got the above error when i ran with the debug mode . and the error was thrown from document1.document()->setHtml(hex); this line of code .
-
hex
is doubtless some illegal HTML (not HTML at all). -
You persist in trying to use
document()->setHtml(...)
followed bydocument()->setPlainText(data)
. If you do not believe me that you cannot use both (the second will simply replace the first), why don't you read the docs or try a small test for yourself so that you know why it won't work?
-
-
@VRonin i tried the same way as yours (QTextCursor cursor(textDocument);) but it says
mainwindow.cpp:107: error: 'textDocument' was not declared in this scope
QTextCursor cursor(textDocument);
^ -
@JonB I agree with u sir. But i am in a situation that i require to use both . Thats why keep on asking about it. Dont Mistake.
. It shows like this.
-
@VRonin i tried the same way as yours (QTextCursor cursor(textDocument);) but it says
mainwindow.cpp:107: error: 'textDocument' was not declared in this scope
QTextCursor cursor(textDocument);
^@ManiRon said in How to use both the properties of Qtextdocument:
@VRonin i tried the same way as yours (QTextCursor cursor(textDocument);) but it says
mainwindow.cpp:107: error: 'textDocument' was not declared in this scope
QTextCursor cursor(textDocument);
^The error message tells you exactly what is wrong with your code, nothing to add by showing screenshots. You cannot expect to copy @VRonin's suggestion verbatim without any attempt to understand what it is doing and what you need to do to complete it. Why don't you have a look in the docs at
QTextCursor
's constructors? He wants you to understand what is wrong and deal with it, for your own long-term benefit. -
@ManiRon said in How to use both the properties of Qtextdocument:
@VRonin i tried the same way as yours (QTextCursor cursor(textDocument);) but it says
mainwindow.cpp:107: error: 'textDocument' was not declared in this scope
QTextCursor cursor(textDocument);
^The error message tells you exactly what is wrong with your code, nothing to add by showing screenshots. You cannot expect to copy @VRonin's suggestion verbatim without any attempt to understand what it is doing and what you need to do to complete it. Why don't you have a look in the docs at
QTextCursor
's constructors? He wants you to understand what is wrong and deal with it, for your own long-term benefit. -
@JonB header has top left corner one image and top right corner one image and a title at the middle of the two images, and after that i want insert my texts. This much things i want to do . Is there any way ? :(
@ManiRon said in How to use both the properties of Qtextdocument:
@JonB header has top left corner one image and top right corner one image and a title at the middle of the two images, and after that i want insert my texts. This much things i want to do . Is there any way ? :(
Assuming this has nothing to do with PDF (sometimes you talk about the PDF header or "inserting PDF", I'm never sure), this sounds like you want to insert an image into your document? Have a read of http://doc.qt.io/qt-5/richtext-cursor.html and http://doc.qt.io/qt-5/qtextcursor.html#insertImage-2 ? I really think you need to do some reading of this sort of stuff to get an idea of what you can do with
QTextDocument
&QTextCursor
. -
@ManiRon said in How to use both the properties of Qtextdocument:
@JonB header has top left corner one image and top right corner one image and a title at the middle of the two images, and after that i want insert my texts. This much things i want to do . Is there any way ? :(
Assuming this has nothing to do with PDF (sometimes you talk about the PDF header or "inserting PDF", I'm never sure), this sounds like you want to insert an image into your document? Have a read of http://doc.qt.io/qt-5/richtext-cursor.html and http://doc.qt.io/qt-5/qtextcursor.html#insertImage-2 ? I really think you need to do some reading of this sort of stuff to get an idea of what you can do with
QTextDocument
&QTextCursor
. -
@ManiRon said in How to use both the properties of Qtextdocument:
@JonB header has top left corner one image and top right corner one image and a title at the middle of the two images, and after that i want insert my texts. This much things i want to do . Is there any way ? :(
Assuming this has nothing to do with PDF (sometimes you talk about the PDF header or "inserting PDF", I'm never sure), this sounds like you want to insert an image into your document? Have a read of http://doc.qt.io/qt-5/richtext-cursor.html and http://doc.qt.io/qt-5/qtextcursor.html#insertImage-2 ? I really think you need to do some reading of this sort of stuff to get an idea of what you can do with
QTextDocument
&QTextCursor
. -
@JonB Its just a title where i want to place my company logo on the left and right top corner and the titke as my project .
@ManiRon
Not viaQTextDocument
. You'd have to look at manipulating the PDF output, which is a different matter.Something like https://forum.qt.io/topic/74643/qtextdocument-to-pdf-with-watermarks-and-header-footer-filesize-too-large might give you some ideas. I do not guarantee whether that is good/the right approach, but it might be.
-
@ManiRon
Not viaQTextDocument
. You'd have to look at manipulating the PDF output, which is a different matter.Something like https://forum.qt.io/topic/74643/qtextdocument-to-pdf-with-watermarks-and-header-footer-filesize-too-large might give you some ideas. I do not guarantee whether that is good/the right approach, but it might be.
-
@ManiRon This is my report with an example image inserted. the two images with the Name REPORT are the title of the document and that "sdvzfdvzsfdv" is the text that i wanted to insert.
@ManiRon
If you don't want to do this via thepaint()
suggested in the link I posted above, you could try with eitherQTextCursor::insertImage()
or you could try writing the whole thing in HTML and seeing ifQTextCursor::insertHtml()
accepts it or not, I don't know. -
@ManiRon
If you don't want to do this via thepaint()
suggested in the link I posted above, you could try with eitherQTextCursor::insertImage()
or you could try writing the whole thing in HTML and seeing ifQTextCursor::insertHtml()
accepts it or not, I don't know. -
@ManiRon
If you don't want to do this via thepaint()
suggested in the link I posted above, you could try with eitherQTextCursor::insertImage()
or you could try writing the whole thing in HTML and seeing ifQTextCursor::insertHtml()
accepts it or not, I don't know. -
@JonB but with this QTextCursor::insertImage() property whether i can place the image anywhere ?
-
@ManiRon
You can insert it wherever you can navigate aQTextCursor
to. Frankly I don't understand from what you have written where exactly it is you want it, so I don't know whether you can navigate there.