QTextEdit::setAlignment not working.
the following code,
CardLore.setParent(&MainWidget); CardLore.setReadOnly(true); QString text = "foo foofoofoo foofoo foofoofoofoo foofoo foofoofoofoo foo foofoo foofoofoo foo foofoo"; CardLore.setText(text); CardLore.setAlignment(Qt::AlignJustify); CardLore.resize(447, 98); CardLore.move(401, 501);
where CardLore is a QTextEdit object, fails to justify the text and I don't know why. What am I missing? I've googled my problem but couldn't find a thread about it that was either recent or working.
Thanks in advance for any help.
Hi and welcome to devnet,
Calling setAlignment will make the next paragraph use the alignment. So you have to do:
Hope it helps
Thanks for your reply!
Unfortunately this didn't work for me, although it works if I replace Qt::AlignJustify with Qt::AlignRight (I have no idea why), but that's not what I want :(
QPainterObject.drawText(QRect(34, 475, 350, 75), Qt::AlignJustify | Qt::TextWordWrap, someText);
does wrap the text, but seems unabled to justify it as well. So either I'm using Qt::AlignJustify the wrong way, or Qt::AlignJustify doesn't work on Ubuntu.
Are you sure it's not the size of your widget that makes it seems like it's not justified ?
Well the text was wrapped and each line ended at a different place, so it was clear that the text wasn't justified.
You were using a QTextEdit and now you are using a painter. What is your current code ?
I apologize, my main concern was about QTextEdit, and I happened to try to do that (as a totally different issue) on a QImage with QPainter. That failed as well, and I mistook this thread for my newer problem.
I'm still using the code in the OP.