PDA

View Full Version : Question about align



Archa4
14th March 2011, 09:06
I tried to do a simple thing:


painter->drawText(rect, Qt::AlignTop && Qt::AlignRight, str);
painter->drawLine(rect.topLeft(), rect.bottomRight());
painter->drawText(rect, Qt::AlignBottom, "ASD");

But it didn't work...
The top line get's aligned only top, but not top + right.
How can i get it to align top + right?
I think it has something to do with flags, but i could not confirm that idea.

wysota
14th March 2011, 09:16
You are using a wrong bitwise operation. Firstly && is not a bitwise operation so Qt::AlignTop && Qt::AlignRight returns "true" (or "1") is neigher of the two components are "0". Secondly "&&" is a conjunction operator and not alternative which is what you need.

painter->drawText(rect, Qt::AlignTop|Qt::AlignRight, str);

stampede
14th March 2011, 09:17
painter->drawText(rect, Qt::AlignTop | Qt::AlignRight, str);
More info: C bitwise operators (http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/)
-------
looks like I'm too slow

Archa4
14th March 2011, 09:18
Thanks it worked :)
I also tried "Qt::AlignTop + Qt::AlignRight" and it worked to.

wysota
14th March 2011, 09:36
I also tried "Qt::AlignTop + Qt::AlignRight" and it worked to.
In this particular situation yes but in general this is not correct. Consider this:

Qt::AlignTop+Qt::AlignTop
Logically this should be Qt::AlignTop but it won't be, Thus you should use "|".