how to align an image vertically?
i need a WImage to be rendered in the middle of root(). how can i do that?
RE: how to align an image vertically? - Added by Wim Dumon 9 months ago
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.
RE: how to align an image vertically? - Added by Аз Есмь 9 months 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.
RE: how to align an image vertically? - Added by Koen Deforche 9 months ago
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 ...
RE: how to align an image vertically? - Added by Аз Есмь 8 months 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 8 months ago
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.