how to align an image vertically?
Added by Аз Есмь almost 13 years ago
hello,
i need a WImage to be rendered in the middle of root(). how can i do that?
thank you
Replies (5)
RE: how to align an image vertically? - Added by Wim Dumon almost 13 years ago
Two possibilities:
Set a layout manager on root, and set AlignCenter | AlignMiddle as alignemnt flags.
If you know the size of your image, there's also a pure CSS trick using absolute positioning - google for it.
BR,
Wim.
RE: how to align an image vertically? - Added by Аз Есмь almost 13 years ago
okay, i wrote the code as follows:
Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(root());
layout->addWidget(new Wt::WImage("image.jpg"), Wt::AlignCenter | Wt::AlignMiddle);
but i've got the image resized to fill the whole page. i've even tried to resize() it, but to no avail.
what's wrong?
RE: how to align an image vertically? - Added by Koen Deforche almost 13 years ago
Hey,
The second argument to addWidget() is the stretch factor. Unfortunately, for backward compatibility we made the int cast operator available on WFlags, so the compiler isn't issuing any warning for this code.
I've been bitten by it many times too, so it would be a good moment to revise the usefulness of this casting operator versus the cost ...
Regards,
koen
RE: how to align an image vertically? - Added by Аз Есмь almost 13 years ago
thank you, Koen. the 2nd argument is indeed the stretch factor. i overlooked that fact.
on the plus side, i began to use CSS instead of WLayout and have never regreted about that.
nevertheless, i don't think it's a good idea to abandon backward compatibility.
and the question that i'd actually like to ask is why did you choose the stretch factor to be int and not bool?
RE: how to align an image vertically? - Added by Koen Deforche almost 13 years ago
Hey,
I absolutely agree that you should favor CSS over layout managers. The only reason for layout managers is when CSS cannot express what you want.
Stretch is an int because you can give a different weight to different cells.
Regards,
Koen