PDA

View Full Version : multiline drawtext draw all in same line



ptr
23rd January 2013, 10:15
hi,

i will draw a multiline text with alignment AlignBottom, but it draw all lines in same line.

fontAlign = Qt::AlignHCenter | Qt::AlignBottom;
p->drawText(rect, fontAlign, str);

see attachment

what can I do, thanks

Peter

wysota
23rd January 2013, 10:50
What do rect and str contain?

ptr
23rd January 2013, 11:00
hi

rect {x1=135 y1=165 x2=449 y2=359}
str:

"
Hier
Text
eingeben
"

here a pic with Top alignment

8613

wysota
23rd January 2013, 11:11
So it works for top but fails for bottom, correct? Can you prepare a minimal compilable example reproducing the problem?

This seems to work fine:

#include <QtGui>

class Widget : public QWidget {
public:
Widget() : QWidget() {}
protected:
void paintEvent(QPaintEvent *) {
QPainter p(this);

p.drawText(rect(), Qt::AlignHCenter|Qt::AlignBottom, "Hier\nText\neingeben");
}
};

int main(int argc, char **argv) {
QApplication app(argc, argv);
Widget w;
w.resize(449, 359);
w.show();
return app.exec();
}

Did you remember to put newline characters (\n) in your string? I can't see them in what you posted.

ptr
23rd January 2013, 11:15
ok thanks,
I'll try it tomorrow

ptr
24th January 2013, 10:22
hi,

now works fine.
It was the (\ n), my fault.

thanks