PDA

View Full Version : Vertical text in a QTextDocument



Angelo Moriconi
11th January 2008, 10:11
I need to have a QTextDocument that display vertical text. Probably, reading the documentation, I need to create a new layout that draw every single character moving everytime down.

Just to avoid confusion I don't want to rotate also the characters (I know that I can simple rotate all the widget using a QTransform) I need to have something like that:

H
E
L
L
O

W
O
R
L
D

There is a simple way to have vertical text inside a QTextDocument or I need to reimplement a QDocumentLayout ?

Thanks in advance,

Angelo

high_flyer
14th January 2008, 15:57
does it mean you want your QTextDocument to be just one vertical line?
What re the rules for this vertical layout?

Angelo Moriconi
6th February 2008, 09:59
No, I need vertical text in multiple lines.
I want to write vertically and then , when I press return going in another line (on the right).

So, vertical text drawing from left to right, like Japanese writing.

Currently I cannot find a solution, I have to study the QTextLayout in order to create a custom layout suitable for this.

Best,

Angelo

wysota
6th February 2008, 10:07
You'll need to provide your own layout engine derived from QAbstractTextDocumentLayout.

ashukla
6th February 2008, 10:45
Dear Angelo!


QStringList sl;
sl=txtScrollEdit->toPlainText().split(" ");
txtScrollEdit->setText(sl.join("\n\n"));
txtScrollEdit->setWordWrapMode (QTextOption::WrapAnywhere);// txtScrollEdit is QTextEdit
txtScrollEdit->setLineWrapMode(QTextEdit::FixedColumnWidth);
txtScrollEdit->setLineWrapColumnOrWidth(1);
Hope it helps!

Angelo Moriconi
6th February 2008, 16:22
Thanks Ashuklafor the quick reply.
Probably this method should work, but I currently use a QGraphicsTextItem in which there isn't the possibility to set the lineWrapMode.

I must use this kind of widget since currently I need to scale the text according to the view and the textEdit widget doesn't allow to do that. But this is another issue :)

Best,

Angelo

ashukla
7th February 2008, 06:30
Dear Angelo!

QGraphicsTextItem *item=new QGraphicsTextItem;
item->setDocument(txtScrollEdit); //txtScrollEdit is a QTextEdit
By the above way you can set the lineWrapMode implicitly.
Hope its help!