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> element.
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.
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 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 /navigation/anchor.
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 Bootstrap theme. 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.
Instead of using the default size, you can apply a larger or smaller size to a button. Add the style class .btn-lg or .btn-sm to change the size.
You can create a primary button - one that is more striking - by adding the .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).