QtGradientDialog ClassThe QtGradientDialog class provides a dialog for specifying gradients. More... #include <QtGradientDialog> Inherits: QDialog. Public Types
Properties
Public Functions
Static Public Members
Protected Functions
Additional Inherited Members
Detailed DescriptionThe QtGradientDialog class provides a dialog for specifying gradients. The gradient dialog's function is to allow users to edit gradients. For example, you might use this in a drawing program to allow the user to set the brush gradient.
Starting from the top of the dialog there are several buttons: [Missing image qtgradientdialogtopbuttons.png] The first three buttons allow for changing a type of the gradient (QGradient::Type), while the second three allow for changing spread of the gradient (QGradient::Spread). The last button shows or hides the details extension of the dialog. Conceptually the default view with hidden details provides the full functional control over gradient editing. The additional extension with details allows to set gradient's parameters more precisely. The visibility of extension can be controlled by detailsVisible property. Moreover, if you don't want the user to switch on or off the visibility of extension you can set the detailsButtonVisible property to false. Below top buttons there is an area where edited gradient is interactively previewed. In addition the user can edit gradient type's specific parameters directly in this area by dragging appropriate handles.
In the middle of the dialog there is an area where the user can edit gradient stops.
The top part of this area contains stop handles, and bottom part shows the preview of gradient stops path. In order to create a new gradient stop double click inside the view over the desired position. If you double click on existing stop handle in the top part of the view, clicked handle will be duplicated (duplicate will contain the same color). The stop can be activated by clicking on its handle. You can activate previous or next stop by pressing left or right key respectively. To jump to the first or last stop press home or end key respectively. The gradient stops editor supports multiselection. Clicking a handle holding the shift modifier key down will select a range of stops between the active stop and clicked one. Clicking a handle holding control modifier key down will remove from or add to selection the clicked stop depending if it was or wasn't already selected respectively. Multiselection can also be created using rubberband (by pressing the left mouse button outside of any handle and dragging). Sometimes it's hard to select a stop because its handle can be partially covered by other handle. In that case the user can zoom in the view by spinning mouse wheel. The selected stop handles can be moved by drag & drop. In order to remove selected stops press delete key. For convenience context menu is provided with the following actions:
The bottom part of the QtGradientDialog contains a set of widgets allowing to control the color of the active and selected stops.
The color button shows the color of the active gradient stop. It also allows for choosing a color from standard color dialog and applying it to the active stop and all selected stops. It's also possible to drag a color directly from the color button and to drop it in gradient stops editor at desired position (it will create new stop with dragged color) or at desired stop handle (it will change the color of that handle). To the right of color button there is a set of 2 radio buttons which allows to switch between HVS and RGB color spec. Finally there are 4 color sliders working either in HSVA (hue saturation value alpha) or RGBA (red green blue alpha) mode, depending on which radio button is chosen. The radio buttons can be controlled programatically by spec() and setSpec() methods. The sliders show the color of the active stop. By double clicking inside color slider you can set directly the desired color. Changes of slider's are applied to stop selection in the way that the color component being changed is applied to stops in selection only, while other components remain unchanged in selected stops (e.g. when the user is changing the saturation, new saturation is applied to selected stops preventing original hue, value and alpha in multiselection). The convenient static functions getGradient() provide modal gradient dialogs, e.g.: bool ok; QGradient gradient = QtGradientDialog::getGradient(&ok, QRadialGradient(), this); if (ok) { // the user clicked OK and gradient is set to the gradient the user selected } else { // the user canceled the dialog; gradient is set to the initial // value, in this case radial gradient } In order to have more control over the properties of QtGradientDialog use standard QDialog::exec() method: bool detailsVisible; QColor::Spec spec; QGradient gradient; QtGradientDialog dlg(this); dlg.setDetailsVisible(detailsVisible); dlg.setSpec(spec); dlg.setGradient(gradient); if (dlg.exec() != QDialog::Accepted) return; gradient = dlg.gradient(); // detailsVisible and spec properties can be changed interactively by the user too, // we store the values of these properties for the next time QtGradientDialog is executed. detailsVisible = dlg.detailsVisible(); spec = dlg.spec(); See also Gradient View Example. Property Documentation
|
[Missing image qtgradientdialogbackgroundcheckered.png] | [Missing image qtgradientdialogbackgroundtransparent.png] |
QtGradientDialog dlg; dlg.setBackgroundCheckered(true); | QtGradientDialog dlg; dlg.setBackgroundCheckered(false); |
When this property is set to true (the default) widgets inside gradient dialog like color button, color sliders, gradient stops editor and gradient editor will show checkered background in case of transparent colors. Otherwise the background of these widgets is transparent.
Access functions:
bool | isBackgroundCheckered() const |
void | setBackgroundCheckered(bool checkered) |
This property holds whether the details button allowing for showing and hiding details extension is visible.
When this property is set to true (the default) the details button is visible and the user can show and hide details extension interactively. Otherwise the button is hidden and the details extension is always visible or hidded depending on the value of detailsVisible property.
Access functions:
bool | isDetailsButtonVisible() const |
void | setDetailsButtonVisible(bool visible) |
See also detailsVisible.
This property holds whether details extension is visible.
When this property is set to true the details extension is visible. By default this property is set to false and the details extension is hidden.
Access functions:
bool | detailsVisible() const |
void | setDetailsVisible(bool visible) |
See also detailsButtonVisible.
This property holds the gradient of the dialog.
Access functions:
QGradient | gradient() const |
void | setGradient(const QGradient & gradient) |
Constructs a gradient dialog with parent as parent widget.
Destroys the gradient dialog
Executes a modal gradient dialog, lets the user to specify a gradient, and returns that gradient.
If the user clicks OK, the gradient specified by the user is returned. If the user clicks Cancel, the initial gradient is returned.
The dialog is constructed with the given parent. caption is shown as the window title of the dialog and initial is the initial gradient shown in the dialog. If the ok parameter is not-null, the value it refers to is set to true if the user clicks OK, and set to false if the user clicks Cancel.
This method calls getGradient(ok, QLinearGradient(), parent, caption).
Sets the current QColor::Spec to spec used for the color sliders in the dialog.
See also spec().
Returns the current QColor::Spec used for the color sliders in the dialog.
See also setSpec().