Unsolved how to give the html tag line to QString
-
I have been trying to give the HTML tag line to QString variable
example QString qHtml = ("<button type="button">Click Me!</button>");
but it is throwing error, is there any way i should define it
-
but it is throwing error
Which error is thrown by whom?
QString qHtml = "<button type=\"button\">Click Me!</button>";
should at least compile fine. -
error: 'button' was not declared in this scope
QString qPrint = "("<button type="button">Click Me!</button>")";this the error
^ -
Yeah, because your example
QString qPrint = "("<button type="button">Click Me!</button>")";
is different from your first example and different from mine. Just use the version in my post above.
-
@aha_1980
error: expected ',' or ';' before 'button'
QString qPrint = "<button type="button">Click Me!</button>";
^Again error
-
@ManiRon Ah, sorry. You need to escape the inner quotation marks. I've edited my post above.
-
Ya i tried with the edited code but it is not creating the button and it just displays the text click me in the html file
-
@aha_1980 this just prints the click me in the html file
-
@ManiRon maybe you must assign a stylesheet ? how do you renderer it ?
-
@cfdev i am not getting you
-
@ManiRon what is your html engine ?
your application with qtextdocument or QtWebEngine or other ? -
@cfdev QTextBrowser and QTextStream
QTextBrowser qTextRep;
QTextStream qData(&qHtmlFile);
qTextRep.document()->setHtml(qHtml);qData << qTextRep.document()->toHtml();
-
@ManiRon said in how to give the html tag line to QString:
QTextBrowser
Ok, see https://doc.qt.io/qt-5/richtext-html-subset.html, because last attributs of html are not supported like "<button>".
-
@ManiRon
If I understand @cfdev's reference right, you will not be able to put a<button>
tag (or for that matter an<input type="button">
) on aQTextBrowser
. I could be wrong(!), but I think it allows browsing only, it does not support adding "interaction" tags. It does support<a href=...>
, though presumably for a URL only not JavaScript, if that might give what you want.I have no idea what you're trying to achieve, but if it exceeds what
QTextBrowser
can do are you at least aware of https://doc.qt.io/qt-5/qwebengineview.html ? That is a Chromium-browser-widget, much more "heavyweight" thanQTextBrowser
but might be what you are looking for? -
Actually i am trying to create a button to make the html report to be printed to a pdf . by giving the window.print() call
-
@ManiRon
Again, I could be wrong :), but that is JavaScript and I don't thinkQTextBrowser
is going to allow that.window.print()
is JavaScript and I don't think that's going to work. Try something like:<a href="window.print()">Print me</a> <a href="javascript:window.print()">Print me</a>
and see what happens (probably nothing).
You might instead have your code pull the HTML back from the
QTextBrowser
and do it yourself. Or, theQWebEngine
I told you about will (should) allowwindow.print()
; alternatively, as I do in my code, it allows you to handle printing yourself via e.g. https://doc.qt.io/qt-5/qwebenginepage.html#printToPdf. You can force using PDF either to the printer directly, or to a file, and you can also print directly to printer without going via PDF. -
@JonB said in how to give the html tag line to QString:
"javascript:window.print()
I tried both and this one (<a href="javascript:window.print()">Print me</a>) worked and asked for which printer to use and i select one suddenly it says some error has occured
-
@ManiRon said in how to give the html tag line to QString:
some error has occured
So if you need any input to that, the actual error would be helpful ! :)