Wt provides different kinds of button widgets. With a WPushButton a user can execute a command by a click action, e.g. an OK button is generally used for confirming actions and closing the window while a Cancel button is used for canceling actions and closing the window.
WPushButton corresponds to an HTML
A push button typically responds to
You may decorate a push button with a background image to create a clickable image. As a descendant of class WFormWidget, push buttons can be disabled or enabled.
A push button can be designated to be pushed only once and as a result execute a command only once.
You can also associate navigation with a button using
WPushButton::setLink(). With this method you can change the
internal path of the application. As a result the button behaves as an
anchor. This is similar to how a
WMenuWidget or a WTabWidget works. See the menu
Navigation for more details.
With a push button you can execute an action while navigating to a
hyperlink target at the same time using
This method accepts a WLink as parameter.
In the example below, the internal path is changed from
/forms/button (the path associated with the current web page) to
A drop down button is a button with a drop-down menu. It could be used to extend a line edit with possible actions on the input. Usually the menu items are links.
You can add different styles to buttons to change the color, the size,
the positioning, etc. using style classes from the
Button styles can be applied to anything with the
applied. However, for the best rendering, apply these to hyperlinks
<a>) and button controls (
The following table provides an overview of the standard color classes
and visualizes the effect on a button. The
.btn class is applied
to a button control by default; you only have to set additional classes.
Instead of using the default size, you can apply a larger or smaller size
to a button. Add the style class
.btn-sm to change the size.
You can create a primary button - one that is more striking - by adding
.btn-primary style to it.
Usually, a form ends with a group of actions (buttons). When placed within a
.row, the buttons will automatically indent to line
up with the form controls (See the example at
Forms > Form model).