1 Attachment(s)
Vertical Orientation of Text.
Code:
#include <QtGui>
public:
protected:
int leading = fontMetrics.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
if (!line.isValid())
break;
line.setLineWidth(9);
//line.setNumColumns (1);
height += leading;
line.
setPosition(QPoint(0, height
));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout.endLayout();
pe.setWidth(4);
pe.setColor(Qt::red);
p.setPen(pe);
textLayout.
draw(&p,
QPoint(0,
0));
}
};
int main(int argc, char **argv){
W w;
w.show();
w.resize(300,200);
return app.exec();
}
I am getting the output as attachments;
but I wants as
Quote:
H
e
l
l
o
H
o
w
a
r
e
y
o
u
!
What should I do in code for this;
Re: Vertical Orientation of Text.
The easiest way is to add a newline after every character.
Re: Vertical Orientation of Text.
Quote:
Originally Posted by
wysota
The easiest way is to add a newline after every character.
But it is not a way of vertical orientation of text.
I am facing the same problem in the below thread specially for white space character.
Space problem in QTextEdit
Re: Vertical Orientation of Text.
If you want to use the text layout object, then at least set the line width before creating lines. You can use QFontMetrics to check how wide the line should be to incorporate one character of the current font.
Re: Vertical Orientation of Text.
Quote:
If you want to use the text layout object, then at least set the line width before creating lines
How a way I set the line before creating the text layout object.
Please suggest me a function for that or give me a example.
Re: Vertical Orientation of Text.
Re: Vertical Orientation of Text.
Quote:
Originally Posted by
wysota
Probably, this is function of QTextLine. How a way I use in my code?
Re: Vertical Orientation of Text.
Please take a look at the example in QTextLayout docs.
Re: Vertical Orientation of Text.
Quote:
Originally Posted by
wysota
I have seen already and by the use of it I developed this above code. But QTextLayout::setLineWidth() I am not getting this function to set the text layout width previously before the line create.
Re: Vertical Orientation of Text.
Set it after you create the line but before you create another... The point is to force a single character on each line. Or consider not using the text layout at all and simply drawing each character yourself using QPainter::drawText.