html text can not be justified on both(left and right) sides in qlabel, qtextbrowser and qtextedit
-
html text is aligned only to left or right, but not both in qlabel, qtextbrowser or qtextedit. Did anyone have the same problem before?
I know QWebengineView works with html text for justfied alignment.#include <QApplication> #include <QTextEdit> int main(int argc, char *argv[]) { QApplication app(argc, argv); // Create a QTextEdit QTextEdit textEdit; textEdit.setAlignment( Qt::AlignJustify ); // Set HTML content with justified text alignment QString htmlContent = "<html><body>" "<p style='text-align:justify;'>This is a sample text with justified alignment.Additional paragraphs can be added as needed." "Additional paragraphs can be added as needed.This is a sample text with justified alignment.</p>" "</body></html>"; textEdit.setHtml(htmlContent); // Remove the border using a style sheet textEdit.setStyleSheet("border: none;"); // Show the QTextEdit textEdit.show(); return app.exec(); }
Linux 22.04 and Qt 5.15.3
-
@Pl45m4 It is not a HTML thing. QWebEngineView justifies the html text well. I guess these widgets do not support enough html features. When I use QWebEngineView, it creates a spacing at its top and bottom and I can not reduce it.
@JoeCFD You can use plain HTML instead of CSS:
<p align='justify'>
. -
html text is aligned only to left or right, but not both in qlabel, qtextbrowser or qtextedit. Did anyone have the same problem before?
I know QWebengineView works with html text for justfied alignment.#include <QApplication> #include <QTextEdit> int main(int argc, char *argv[]) { QApplication app(argc, argv); // Create a QTextEdit QTextEdit textEdit; textEdit.setAlignment( Qt::AlignJustify ); // Set HTML content with justified text alignment QString htmlContent = "<html><body>" "<p style='text-align:justify;'>This is a sample text with justified alignment.Additional paragraphs can be added as needed." "Additional paragraphs can be added as needed.This is a sample text with justified alignment.</p>" "</body></html>"; textEdit.setHtml(htmlContent); // Remove the border using a style sheet textEdit.setStyleSheet("border: none;"); // Show the QTextEdit textEdit.show(); return app.exec(); }
Linux 22.04 and Qt 5.15.3
-
What happens if you
widget->setAlignment(Qt::AlignJustify)
afterwards (after setting the text/html)?
Does it work at all? If so, then it must be something with the HTML -
@Pl45m4 It is not a HTML thing. QWebEngineView justifies the html text well. I guess these widgets do not support enough html features. When I use QWebEngineView, it creates a spacing at its top and bottom and I can not reduce it.
@JoeCFD You can use plain HTML instead of CSS:
<p align='justify'>
. -
@JoeCFD You can use plain HTML instead of CSS:
<p align='justify'>
.@Chris-Kawa Thanks for your reply, Chris. I tried it and only one line is displayed. I will look into this later.
-
@Chris-Kawa Thanks for your reply, Chris. I tried it and only one line is displayed. I will look into this later.
@JoeCFD I don't have Qt 5 at hand, but it works in 6.6.
-
@JoeCFD I don't have Qt 5 at hand, but it works in 6.6.
@Chris-Kawa
I can confirm it works in Qt 5.15.2. -
@JoeCFD I don't have Qt 5 at hand, but it works in 6.6.
@Chris-Kawa Tested it. Works nicely. Many thanks.
-
J JoeCFD has marked this topic as solved on