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.
A WPushButton corresponds to an HTML <button>
A push button typically responds to clicked() events.
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.
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 WPushButton::setLink().
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
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 .btn class
applied. However, for the best rendering, apply these to hyperlinks
(<a>) and button controls (<button>) only.
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.
Usually, a form ends with a group of actions (buttons). You can make the
action section more striking compared to the upper input field section by
adding the style class .form-actions. When placed within a
.form-horizontal, the buttons will automatically indent to line
up with the form controls (See the example at
Forms > Form model).