Wt provides different kinds of button widgets. The WCheckBox class provides independent on/off options in contrast to WRadioButtons which are usually mutually exclusive.
An instance of WCheckBox
corresponds to an HTML
<input type="checkbox">
element.
Next to being checked or unchecked, a checkbox can be configured
to allow a third state, Wt::PartiallyChecked
, which can
be used to indicate that it isn't entirely checked,
e.g. if only some of the files in a folder are selected, then
the checkbox for that folder would be partially checked. In the
example below, the third checkbox demonstrates this tristate
behaviour.
By default, check boxes will appear on the same line.
Since by default, check boxes are inline, you will need to use
setInline(false)
to let them stack vertically.
#include <Wt/WCheckBox.h>
#include <Wt/WContainerWidget.h>
auto result = std::make_unique<Wt::WContainerWidget>();
Wt::WCheckBox *cb;
cb = result->addNew<Wt::WCheckBox>("Check me!");
cb->setInline(false);
cb->setChecked(true);
cb = result->addNew<Wt::WCheckBox>("Check me too!");
cb->setInline(false);
cb = result->addNew<Wt::WCheckBox>("Check me, I'm tristate!");
cb->setInline(false);
cb->setTristate();
cb->setCheckState(Wt::CheckState::PartiallyChecked);