Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. html
    Log in to post

    • UNSOLVED QTextEdit HTML font issue
      General and Desktop • qtextedit html • • wazzdaman  

      4
      0
      Votes
      4
      Posts
      64
      Views

      I have run into the same problem using Qt 5.15.2. Setting fontFamily(name) on QTextEdit will not change the font name, but append it as a secondary name, causing QTextEdit to not show the correct font, since it uses the first font name. This does not happen if QTextEdit is set with a plain text, but setHtml(ht) will cause the problem. The following code example shows the problem without using UI. QTextEdit te; // Start by setting a text using Arial te.setFontFamily("Arial"); te.setText("ABC"); // The html output shows ... font-family:'Arial' QString html = te.toHtml(); qDebug() << "html 1" << html; // Then select all text and change font to Calibri QTextCursor crs = te.textCursor(); crs.movePosition(QTextCursor::Start); crs.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); te.setTextCursor(crs); te.setFontFamily("Calibri"); // The html output is still good with ... font-family:'Calibri' html = te.toHtml(); qDebug() << "html 2" << html; // Change the font back to Arial te.setFontFamily("Arial"); // The html output is still good with ... font-family:'Arial' html = te.toHtml(); qDebug() << "html 3" << html; // Now set the text using the good html with Arial te.setHtml(html); // Again select all text and set the font to Calibri crs = te.textCursor(); crs.movePosition(QTextCursor::Start); crs.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); te.setTextCursor(crs); te.setFontFamily("Calibri"); // Now the html output is bad with ... font-family:'Arial','Calibri' html = te.toHtml(); qDebug() << "html 4" << html; The output from above code: html 1 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial';">ABC</span></p></body></html>" html 2 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Calibri';">ABC</span></p></body></html>" html 3 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial';">ABC</span></p></body></html>" html 4 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><head><meta name="qrichtext" content="1" /><style type="text/css">\np, li { white-space: pre-wrap; }\n</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">\n<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Arial','Calibri';">ABC</span></p></body></html>" where the last line with font-family:'Arial','Calibri' is not as expected. It should only say Calibri to work correctly. Kind regards Søren
    • SOLVED Background for QStaticText by html
      General and Desktop • html css qstatictext • • Ejok88  

      3
      0
      Votes
      3
      Posts
      58
      Views

      @Chris-Kawa thanks 🙏
    • UNSOLVED In Laravel, check login always goes back to the login failure page.
      Independent Developers • html css php bootstrap laravel • • Lucky01  

      3
      0
      Votes
      3
      Posts
      117
      Views

      @Paul-Colby thanks this is really helpful
    • UNSOLVED Bookmark Issue when converting HTML to PDF
      General and Desktop • html qprinter pdf bookmarks • • Majed.Y  

      4
      0
      Votes
      4
      Posts
      117
      Views

      @Majed-Y That's can do what you want.... [link text](link url)https://github.com/qpdf/qpdf
    • UNSOLVED build job does not create .html file (Message: file not found)
      Qt for WebAssembly • build html webassembly emscripten emcc • • broko_lee  

      6
      0
      Votes
      6
      Posts
      268
      Views

      In Qt 6.4 (on macos) Debug build does not generate javascript file...
    • UNSOLVED Title attribute of html tag
      QML and Qt Quick • qml html label title • • Cocojambo  

      8
      0
      Votes
      8
      Posts
      339
      Views

      The tag support in Qt objects is really simplistic and nowhere near like a browser. If you want browser type html use webengine. I think webengine is pretty heavy and probably not what you want.
    • SOLVED Set background image on QTextDocument using HTML to generate pdf file
      General and Desktop • html image display pdf qtextdocument • • BillydogTheKid  

      2
      0
      Votes
      2
      Posts
      292
      Views

      I have found the answer! it is about the drawContents method of QTextDocument. There is a second parameter that you need to add in order to see the background image in your document. It's the a QRectF object that represend the size of the rect that the background image will be clipped into. void QTextDocument::drawContents(QPainter *p, const QRectF &rect = QRectF()) Draws the content of the document with painter p, clipped to rect. If rect is a null rectangle (default) then the document is painted unclipped. So what I did is: easuresDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print TextDocument of the Measures into the document pdfPrinter.newPage(); // We inject the current page and continue printing on new page averagesDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print the TextDocument of the Averages into the document pdfPrinter.newPage(); // We inject the current page and continue printing on new page inOutDoc.drawContents(&painter, pdfPrinter.paperRect()); // We print the TextDocument of the Inputs/Outputs into the document pdfPrinter.paperRect is the rectangle of the page without the margin. Also if you want the background image to be printed scaled with no repeat than you need to put the printer into QPrinter::PrinterResolution QPrinter pdfPrinter(QPrinter::PrinterResolution);
    • UNSOLVED Qt printing using html and QTextDocument
      General and Desktop • qtquick html qprinter pdf qtextdocument • • kuntio  

      7
      0
      Votes
      7
      Posts
      529
      Views

      syntax from documentation for border <width>px <border-style> <border-color> That's mean it should be px after border.
    • SOLVED Replace and Remove from html string not working
      General and Desktop • qstring json html • • RekTekk249  

      5
      0
      Votes
      5
      Posts
      284
      Views

      @JKSH Oh wow, you're completely right. I didn't know qDebug() behaved like this, I assumed noquote() was the default. Thanks for the help, I don't know how long it would have taken me to find out.
    • UNSOLVED Read .odt file and loop over characters
      General and Desktop • file html qtextdocument odt • • Tamfub  

      6
      0
      Votes
      6
      Posts
      418
      Views

      @artwaw Yes, it works fine eventually :)
    • SOLVED Can't open an HTML on a specific fragment in QT using hash
      General and Desktop • html qurl qdesktopservice • • a1rltt  

      3
      0
      Votes
      3
      Posts
      304
      Views

      @Bonnie yes, i'm on Windows, thanks for the explaining!
    • UNSOLVED Size of image in text
      QML and Qt Quick • html size height width img • • Cynthia.Roush  

      5
      0
      Votes
      5
      Posts
      575
      Views

      @Jkimmy Thank you for your help.
    • UNSOLVED HTML - SVG images inserted in a text document show ugly
      QML and Qt Quick • image text html svg stretch • • jeanmilost  

      5
      0
      Votes
      5
      Posts
      622
      Views

      Is it possible to to extend QLabel and implement my own paintEvent() that draws the text and draws the svg image? It seems to work, but would problaby take alot of effort to get it right (i.e. to get the image in the right location everytime). void MypLabel::paintEvent(QPaintEvent* event) { QPainter painter(this); const auto pos = QPoint(0, 16); painter.drawText(pos, this->text()); const auto posPixMap = QPoint(30, 0); auto size = QSize(16, 16); auto pixMap = QIcon(":/Resources/smiley.svg").pixmap(size); painter.drawPixmap(posPixMap, pixMap); }
    • UNSOLVED webview security
      QML and Qt Quick • qt quick javascript webview html security • • addr3ss  

      2
      0
      Votes
      2
      Posts
      281
      Views

      @addr3ss No, it's not. Resources are compiled into the executable and can be easily extracted from there. What kine of information is it?
    • UNSOLVED Back button click Android not registered in Qt Webview
      Mobile and Embedded • qml android html qt5.10 • • Ramonn  

      1
      0
      Votes
      1
      Posts
      692
      Views

      No one has replied

    • UNSOLVED Paint shadow inside an QImage or QGraphicsEffect Shadow... html page doc
      General and Desktop • html qgraphicseffect qabstractscroll • • patrik08  

      3
      0
      Votes
      3
      Posts
      1189
      Views

      Tanks .... Compiler accept only this way ...... ;-) #ifdef QT_NO_GRAPHICSEFFECT QImage applyEffectToPics(QImage src, QGraphicsEffect *effect, int extent = 0) { if(src.isNull()) return QImage(); //No need to do anything else! if(!effect) return src; //No need to do anything else! QGraphicsScene scene; QGraphicsPixmapItem item; item.setPixmap(QPixmap::fromImage(src)); item.setGraphicsEffect(effect); scene.addItem(&item); QImage res(src.size()+QSize(extent*2, extent*2), QImage::Format_ARGB32); res.fill(Qt::transparent); QPainter ptr(&res); scene.render(&ptr, QRectF(), QRectF( -extent, -extent, src.width()+extent*2, src.height()+extent*2 ) ); return res; } #endif
    • SOLVED Tag html on QString not applied when contains "\n"
      General and Desktop • qstring html color • • helenebro  

      2
      0
      Votes
      2
      Posts
      955
      Views

      Then use "<br>" instead of "\n"
    • UNSOLVED QTextView changes the HTML string
      General and Desktop • html • • moravas  

      7
      0
      Votes
      7
      Posts
      1238
      Views

      @moravas QTextEdit and buddies only support rich-text and are not suitable for full HTML editing. You should use either QtWebkit module or QtWebEngine (depending on the Qt version you are using) and set the contents editable. But at least QtWebkit (and i guess also QtWebEngine) changes the content a little bit, but the HTML stays valid all the time at least.
    • UNSOLVED Is there a clear way to parse HTML in Qt 5.7
      Qt WebKit • c++ linux windows html parser • • lmofallis  

      15
      0
      Votes
      15
      Posts
      16356
      Views

      @cochise said in Is there a clear way to parse HTML in Qt 5.7: https://github.com/cutelyst/html-qt This is a bit of an old thread but as @cochise said html-qt is an HTML parser, sadly I didn't finish it yet but it follows WHATWG specification on how to implement an HTML parser as HTML is not XML. It's mostly complete but outputting a DOM tree isn't ready yet, so help is welcome.
    • GUI creation guidance / HTML+JS?
      General and Desktop • gui javascript html • • DavideBarranca  

      3
      0
      Votes
      3
      Posts
      1247
      Views

      @raven-worx Thank you for pointing me to the proper documentation pages – I'll have a look at them asap. If the project actually takes off, I'll be a regular in the forums :-) Best regards, – Davide
    • UNSOLVED Parse HTML in Qt 5.7
      General and Desktop • html parsing • • AliReza Beytari  

      12
      0
      Votes
      12
      Posts
      5158
      Views

      @Joel-Bodenmann So I can just use "runJavaScript" function ?! @SGaist No, that was just an example !! :D
    • UNSOLVED How to ensure that an HTML-table in QTextEdit is copied as a table when pasting into for instance Excel?
      General and Desktop • qt5.6 qtextedit html copy • • Jakob  

      5
      0
      Votes
      5
      Posts
      1619
      Views

      @raven-worx Thanx for the suggestion. I think we can go a long way with this, except that we are on Windows and it seems we need some Windows-specific MIME-conversions. We'll try to tinker a bit with that.
    • SOLVED How to display received HTML from an API to webview ?
      QML and Qt Quick • qt quick webview html • • Qjay  

      8
      0
      Votes
      8
      Posts
      3071
      Views

      @Wieland Thanks !! it works fine . I will now complete the QMLbook . i am still noob :/ Thanks for the help
    • SOLVED Saving content from QTextEdit in QFile to a path without a QFileDialog
      General and Desktop • qfile html save • • HenrikSt.  

      8
      0
      Votes
      8
      Posts
      4752
      Views

      @HenrikSt. You got a number of different possibilities suggested. Possibly you are overwhelmed by the different things. Sometimes it is hard for the people answering to know where the real problem was/is. I am not sure now if this might be too detailed for you. Anyway I move forward. I would suggest, if you have not done yet, The example from QFile as also listed by @jsulm and play a bit around. Just change the file name to somthing you need. E.g. QFile file("c:/data/myNewFolder/out.txt"); That is a possibility to specify a complete (absolute) file name. If you are a beginner, I was in that stage before as all the others, there might be a problem with the not existing folder name, if your file not created. There is QDir::mkPath, which is slightly different from mkDir. It may help you in code to ensure that you actually can create the file. The other thing driving me personally nuts is the stupid folder separator for windows, which is a back slash '\'. However, in the mean time you can easily substitute with a forward slash also for most things in Windows (especially Qt). This also part of some of the suggestions. If you have difficulties sometimes it helps for others to post a short section of code and the error message.
    • UNSOLVED QWebView - Pb to display HTML table with rowspan with QT5.5
      General and Desktop • qt5.5 qwebview html css table • • Morgar  

      1
      0
      Votes
      1
      Posts
      1080
      Views

      No one has replied

    • SOLVED QLabel - mouseReleaseEvent to parent - HTML label
      General and Desktop • qlabel html mouseevent • • antonlindgren  

      7
      0
      Votes
      7
      Posts
      2841
      Views

      @mrjj Wow, super. That actually solved it. Thank you so much for your response, your time and your help. I really appreciate it. Thanks. Best regards, Anton
    • SOLVED How to insert a div into a QTextEdit?
      General and Desktop • qtextedit html • • Ctwx  

      4
      0
      Votes
      4
      Posts
      4999
      Views

      I don't really like that As I said - QTextEdit is not an HTML browser. It handles rich text and stores it as styled text blocks. It accepts subset of HTML as input but it does not store it as such. So it doesn't put the content in <p>. It simply has no notion of <p>, <div> etc. at all. That's the source of the remark in the docs, that the stylesheet is only applied on entry. After that there are no <div> to style. The output you get back is a result of another conversion, where every paragraph is simply output as <p>. It does not reflect what you input. Take a look at the link I posted previously. QTextEdit supports only subset of HTML/CSS. It does not support class attribute or a "border" CSS property. How about you try to operate directly on text blocks, and not go through HTML? Here's an example for a chat-like formatting: QTextBlockFormat tbf1; tbf1.setAlignment(Qt::AlignLeft); tbf1.setBackground(Qt::red); QTextBlockFormat tbf2; tbf2.setAlignment(Qt::AlignRight); tbf2.setBackground(Qt::green); ui->textEdit->textCursor().beginEditBlock(); ui->textEdit->textCursor().setBlockFormat(tbf1); ui->textEdit->textCursor().insertText("Wassup?\n"); ui->textEdit->textCursor().endEditBlock(); ui->textEdit->textCursor().beginEditBlock(); ui->textEdit->textCursor().setBlockFormat(tbf2); ui->textEdit->textCursor().insertText("Nothin' much\n"); ui->textEdit->textCursor().insertText("Just playin' a game. How 'bout you?\n"); ui->textEdit->textCursor().endEditBlock(); ui->textEdit->textCursor().beginEditBlock(); ui->textEdit->textCursor().setBlockFormat(tbf1); ui->textEdit->textCursor().insertText("Nothin' much\n"); ui->textEdit->textCursor().endEditBlock();
    • UNSOLVED Changing HTML in QtWebView
      Mobile and Embedded • qml android html qtwebview • • mkeezy  

      1
      0
      Votes
      1
      Posts
      664
      Views

      No one has replied

    • UNSOLVED Qwebview and printer issue(paper size)
      General and Desktop • qwebview html qprinter • • Nouriemm  

      2
      0
      Votes
      2
      Posts
      997
      Views

      Anyone? Any Idea?
    • SOLVED Parsing HTML content
      General and Desktop • html qwebkit • • Bagavathi  

      5
      0
      Votes
      5
      Posts
      1879
      Views

      Good point, I should have added that if it's only to parse html tables, the XML parser should be enough.
    • UNSOLVED Printing QWebView wia QPrinter exceeds page in QPrintPreviewDialog
      General and Desktop • qwebview html qprinter qprintpreviewdi • • SebastianS  

      1
      0
      Votes
      1
      Posts
      714
      Views

      No one has replied

    • UNSOLVED Hint about help documentation
      General and Desktop • html help pdf • • Mark81  

      2
      0
      Votes
      2
      Posts
      966
      Views

      Found: Sphinx
    • QWebView can't show image while Html file using <img src="file://..."> instead <img src="file:///...">
      General and Desktop • file qwebview html local file • • kkkiio  

      1
      0
      Votes
      1
      Posts
      1173
      Views

      No one has replied

    • [Solved] QTextDocument with < and > characters
      General and Desktop • html qtextdocument • • Endless77  

      2
      0
      Votes
      2
      Posts
      878
      Views

      < and > are special characters in html. To display them literally you can use entities: &lt; and &gt; i.e. &lt;80 will result in <80. For a list of possible entities you can scout the web, e.g. here.
    • Render HTML to QPixmap - QWebFrame render() method with transparent background
      Qt WebKit • qpixmap html pixmap qpalette qwebframe • • NiHoTleHot  

      0
      0
      Votes
      0
      Posts
      830
      Views

      No one has replied

    • Calling Qml function From JavaScript (js function called from html)
      General and Desktop • qml javascript html • • pankaj4288  

      8
      0
      Votes
      8
      Posts
      9243
      Views

      I am having more issues in it. When I run this on my andorid devices. It runs fine for teh forst time, but after that it shows me below error- I/chromium(17111): [INFO:CONSOLE(16)] "WebSocket connection to 'ws://127.0.0.1:12345/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED" Can someone help me ?
    • [SOLVED] A png image within HTML code in a QTextEdit
      General and Desktop • image qtextedit html • • sirop  

      8
      0
      Votes
      8
      Posts
      7300
      Views

      @ChrisW67 said: The relative path will be relative to the current working directory of the running process. This is >quite unlikely to be where the source code is (esp. if you are shadow building). Your hint is almost right. Of course, I use the build and not the source directory. The point is that QTextEdit understands the image path within the HTML file also only if the image path is relative to the working dir of the running process and not to the directory of the HTML file. So now my HTML file looks like: <html> <head> <title></title> </head> <body> <h2> TEST <img src='html\images\Diagramm-mit-Dehngrenzen.png' height='480' width='480'> </h2> </body> </html> Which slashes -- forward or backward -- I use, does not matter. However, now neither firefox nor opera show the image as you can understand.
    • Pobieranie strony WWW/HTML z sieci za pomocą Qt
      Polish • html socket internet www strona internet parsowanie parsowanie stro • • Huragan  

      9
      0
      Votes
      9
      Posts
      3303
      Views

      @cybercatalyst Rozumiemy, nie martw się. :) Nigdy, jak dotąd nie korzystałem z klasy QEventLoop. Dzięki za podsunięcie pomysłu, kolejnego sposobu na rozwiązanie tego problemu. :) [ENG] If you don't understand what I wrote, I can rewrite this at english. :) I suppose you speak english. :)
    • HTML img qrc Resource does not display
      Mobile and Embedded • android html ressource • • didu  

      8
      0
      Votes
      8
      Posts
      3517
      Views

      @Malek_Khlif said: @didu said: <RCC> <qresource prefix="/images"> <file>About.ico</file> <file>ic_launcher.png</file> </qresource> </RCC> Edit this resource: <RCC> <qresource prefix="/images"> <file>About.ico</file> <file alias"ic_launcher.png">ic_launcher.png</file> </qresource> </RCC> Also same result :( Otherwise I have other pictures in same qrc that show perfectly on both platforms ! The only difference is that I use html to display this one ! Does anyone have succeed to display on android with html like I do ?