hi, i need to draw text in both vertical layout and horizontal layout. like
hi, i need to draw text in both vertical layout and horizontal layout. like
If your drawing yourself, you can rotate the painter , easiest way i guess![]()
nifei (24th February 2009)
As the previous poster said, use rotate the painter. Look in the analog clock example for how todo this.
In Qt instead of rotating/scaling (e.g. transforming) objects, we transform the painter. It's much easier like this as soon as you get used to;-)
This might also help you:
- http://doc.trolltech.com/qq/qq24-textlayouts.html
- Juergen
Thanks for your suggestion and the linked article, that is a little complicated for my project. May be rotate QPainter is the only way to draw vertical text. I supposed to edit the whole text via QTextDocument and render them to QPainter, if rotating/translating the QPainter, all the text will be rotated or translated.
i think i have to draw the contents of QTextDocument twice, once drawing horizontal text, then rotating the QPainter and drawing the vertical text. is that right?
nifei (24th February 2009)
I traced through QTextDocument : : drawContents (QPainter*) in hopes of QTextFormat's properties being used to control the painter, as i found QTextFormat : : setProperty ( int, QVariant) and guessed we could set QTextFormat : : UserProperty as vertical or horizontal then use this property when using the painter. however, i got lost.
My ideas is to re-implement QTextDocument : : drawContents (QPainter * ) or other functions to get the QTextFormat's properties that have been set by users, According to the UserProperty rotate the painter or not. is this a bad idea?
Qt Code:
// format might be sub class of QTextFormat, for example, QBlockTextFormat { { painter->save(); painter->translate( xoff, yoff);// to correct the text's position painter->rotate(90); // call the basic class's function to draw the text, however rotated. painter->restore(); } else // if no vertical text is needed, call basic class's function }To copy to clipboard, switch view to plain text mode
So I have this code snippet to draw vertical text in a QTextEdit. However, I have 2 problems with this code. The cursor doesn't update when moved, the cursor doesn't blink, and when text is selected it doesn't draw the selection. Any ideas?
Qt Code:
{ painter.rotate(-90); painter.translate(-viewport()->rect().height(),0); selection.cursor = textCursor(); selection.format = textCursor().charFormat(); ctx.cursorPosition = textCursor().position(); ctx.selections.append(selection); document()->documentLayout()->draw(&painter,ctx); }To copy to clipboard, switch view to plain text mode
Bookmarks