duck88
29th July 2014, 03:49
Hi all,
I want to draw text input from keyboard, and display like Japanese style, from right to left and the top to bottom.
I had implemented paintEvent() method in my class to draw text from the top to bottom, my class is inherited from QTextEdit class:
void MyText::paintEvent(QPaintEvent *)
{
QPainter p(viewport());
p.translate(0, 0);
p.rotate(90);
for(int i=0; i< this->document()->toPlainText().size(); ++i) {
QString letter = this->document()->toPlainText().mid(i,1);
p.save();
p.translate(i * 12, 0);
p.rotate(-90);
p.setLayoutDirection(Qt::LeftToRight);
p.drawText(this->rect(), Qt::AlignRight|Qt::AlignTop|Qt::TextWordWrap|Qt::T extWrapAnywhere, letter);
p.restore();
}
}
And result like image:
10531
But I want to text when fit height, it auto word wrap to new column like below image:
10530
How to wrap the text like above image?
Thanks so much!
Best regards!
I want to draw text input from keyboard, and display like Japanese style, from right to left and the top to bottom.
I had implemented paintEvent() method in my class to draw text from the top to bottom, my class is inherited from QTextEdit class:
void MyText::paintEvent(QPaintEvent *)
{
QPainter p(viewport());
p.translate(0, 0);
p.rotate(90);
for(int i=0; i< this->document()->toPlainText().size(); ++i) {
QString letter = this->document()->toPlainText().mid(i,1);
p.save();
p.translate(i * 12, 0);
p.rotate(-90);
p.setLayoutDirection(Qt::LeftToRight);
p.drawText(this->rect(), Qt::AlignRight|Qt::AlignTop|Qt::TextWordWrap|Qt::T extWrapAnywhere, letter);
p.restore();
}
}
And result like image:
10531
But I want to text when fit height, it auto word wrap to new column like below image:
10530
How to wrap the text like above image?
Thanks so much!
Best regards!