Draw vertical text
-
This text is not drawn vertical but horizontal with a linebreak after each character. So add a linebreak after each character in your string you pass to QPainter::drawText()
-
This text is not drawn vertical but horizontal with a linebreak after each character. So add a linebreak after each character in your string you pass to QPainter::drawText()
@Christian-Ehrlicher So if I want draw number as text, I need convert int to string and edit it with insert linebreak?
-
@Christian-Ehrlicher So if I want draw number as text, I need convert int to string and edit it with insert linebreak?
-
@JonB Yes, I understand this. I am interesting edit this text. I need insert linebreaks in right places? And how I can do this easy?
@Christian-Ehrlicher said in Draw vertical text:
So add a linebreak after each character in your string you pass to QPainter::drawText()
-
@Christian-Ehrlicher said in Draw vertical text:
So add a linebreak after each character in your string you pass to QPainter::drawText()
-
@Vlad02 said in Draw vertical text:
How I can insert linebreak after each character?
Iterate over the string and create a new one where you add the character and a linebreak in each iteration. Basic programming stuff.
-
@Vlad02 said in Draw vertical text:
How I can insert linebreak after each character?
Iterate over the string and create a new one where you add the character and a linebreak in each iteration. Basic programming stuff.
@Christian-Ehrlicher what if '\n' not work? I get that: "H\ne\nl\nl\no\n".
QString str; for (QChar ch : text){ str.append(ch); str.append('\n'); }
-
What drawText() function do you use? Please read the documentation about one of them:
This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.
#include <QtWidgets> class Widget : public QWidget { void paintEvent(QPaintEvent *event) override { QPainter p(this); p.drawText(rect(), "T\ne\ns\nt"); } }; int main(int argc, char **argv) { QApplication app(argc, argv); Widget w; w.resize(100,100); w.show(); return app.exec(); }
-
What drawText() function do you use? Please read the documentation about one of them:
This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.
#include <QtWidgets> class Widget : public QWidget { void paintEvent(QPaintEvent *event) override { QPainter p(this); p.drawText(rect(), "T\ne\ns\nt"); } }; int main(int argc, char **argv) { QApplication app(argc, argv); Widget w; w.resize(100,100); w.show(); return app.exec(); }
@Christian-Ehrlicher Oh, thank you very very much!!! I'm sorry for wasting time!