Project

General

Profile

Alignment not working

Added by Adam Skluzada about 7 years ago

Hello,

I'm trying to align text but I can't seem to make it work. When I try to use this:

setContentAlignment(AlignmentFlag::Center);

So the exactly same thing the Hangman example is using, I get this error:

error: ‘setContentAlignment’ was not declared in this scope
   setContentAlignment(AlignmentFlag::Center);

When I specify, that I want to use setContentAlignmentfrom WContainerWidget library like this:

  WContainerWidget::setContentAlignment(AlignmentFlag::Center);

I get this error:

error: cannot call member function ‘void Wt::WContainerWidget::setContentAlignment(Wt::WFlags<Wt::AlignmentFlag>)’ without object
   WContainerWidget::setContentAlignment(AlignmentFlag::Center);

I've also tried to align text like this:

header = root()->addWidget(std::make_unique<WText>("Boolean model of information retrieval"));
header->setTextAlignment(AlignmentFlag::Center);

But that doesn't have any effect.

The only thing that seems to do something is

  header->setMargin(50, Side::Left);

But that's not very useful for me as I would like to have everything in the center.

Thank you.


Replies (1)

RE: Alignment not working - Added by lm at about 7 years ago

It looks like you're calling that from a global or static context. It looks like you're calling setContentAlignment from your Wt::WApplication (which is not a Wt::WContainerWidget). The Wt::WContainerWidget associated with your Wt::WApplication is found at this->root(). Perhaps consider this->root()->setContentAlignment(...)?

I'm not very sure about Wt alignment. I use CSS to do all my alignment-related set up.

    (1-1/1)