Class QSliderLabeled
Custom slider widget used to display text labels along the slider. More...
#include <widgets.h>
Inherits the following classes: QSlider
Public Functions
| Type | Name |
|---|---|
| void | ApplyStyleSheet () Applies a custom style sheet that defines the width and height of the slider based on the orientation of the slider. |
| QSliderLabeled (QWidget * parent=nullptr) Constructor of the labeled QSlider. |
|
| void | SetDisplayLabels (const bool value) Toggles the display of text labels on the slider. |
| void | SetGrooveMargin (const int value) Sets the margin of the groove of the slider. |
| void | SetLabelInterval (const int value) Sets the interval for displaying labels on the slider. |
| void | SetMaxNumberOfLabels (const int value) Sets Maximum number of labels to display in the slider. |
| void | SetSliderSpread (const int value) Sets the maximum spread of the slider. This will represent the maximum height when slider is horizontal and the maximum width when it is vertical. |
Protected Attributes
| Type | Name |
|---|---|
| int | m_grooveMargin = 12 |
| int | m_labelInterval Interval between labels displayed on a slider. |
| int | m_maxNumberOfLabels = 8Maximum number of labels to display. |
| int | m_sliderSpread = 48Size of the slider in pixels. Represents the maximum height when slider is horizontal and the maximum width when it is vertical. |
Protected Functions
| Type | Name |
|---|---|
| bool | event (QEvent * e) override Overrides the event() method from the parent class. |
| void | mouseMoveEvent (QMouseEvent * event) override Triggered when the mouse is moved over the labeled QSlider. |
| void | paintEvent (QPaintEvent * event) override paint event used to draw the labels on the slider. This overrides the paint event, but it calls the original method before drawing the text. |
| void | showEvent (QShowEvent * event) override show event that overwrites the original QSlider show event to apply a custom style sheet before showing the slider. |
Detailed Description
Custom slider widget that displays text corresponding to values in the slider. By default the number of text labels in the slider is set to a maximum of 8. If the calculated number of labels based on the interval and the min and max values in the slider exceed this value, the number of labels is caped.
The text is centered on the corresponding value of the slider while taking into account the groove margins. The margin takes a custom value of 12, this value can be modified depending on what is specified in the style sheet.
Public Functions Documentation
function ApplyStyleSheet
Applies a custom style sheet that defines the width and height of the slider based on the orientation of the slider.
function QSliderLabeled
Constructor of the labeled QSlider.
Parameters:
parentparent class.
function SetDisplayLabels
Toggles the display of text labels on the slider.
This method enables or disables the display of text labels along the slider based on the provided value. When enabled, labels corresponding to values are shown.
Parameters:
valuetrueto enable the display of labels,falseto disable them.
function SetGrooveMargin
Sets the margin of the groove of the slider.
Parameters:
value
function SetLabelInterval
Sets the interval for displaying labels on the slider.
This method configures the interval between the labels displayed along the slider. The labels are generated based on the set interval and the current minimum and maximum values of the slider.
Parameters:
valueThe interval value specifying the spacing between labels. Must be a positive integer.
function SetMaxNumberOfLabels
Sets Maximum number of labels to display in the slider.
Parameters:
valuemaximum number of labels.
function SetSliderSpread
Sets the maximum spread of the slider. This will represent the maximum height when slider is horizontal and the maximum width when it is vertical.
Parameters:
valuethe slider spread.
Protected Attributes Documentation
variable m_grooveMargin
Slider groove margin.
variable m_labelInterval
Interval between labels displayed on a slider.
Determines the step interval for displaying text labels along the slider. This value is used to control the spacing between consecutive labels, allowing customization of the labeling frequency on the slider.
variable m_maxNumberOfLabels
Maximum number of labels to display.
variable m_sliderSpread
Size of the slider in pixels. Represents the maximum height when slider is horizontal and the maximum width when it is vertical.
Protected Functions Documentation
function event
Overrides the event() method from the parent class.
This method is triggered when an event is received by the widget. It specifically handles the QEvent::EnabledChange event and calls the UpdatePainterPen() method to update the painter pen. It then calls the event() method of the parent class to handle any other events. Finally, it returns a boolean value indicating whether the event was handled.
Parameters:
eThe event object.
Returns:
True if the event was handled, false otherwise.
function mouseMoveEvent
Triggered when the mouse is moved over the labeled QSlider.
It shows a tooltip with the corresponding value of the slider at the current mouse position using the QToolTip class. It then calls the mouseMoveEvent() method of the parent class to handle any other events.
Parameters:
eventA pointer to theQMouseEventthat contains information about the mouse move event.
function paintEvent
paint event used to draw the labels on the slider. This overrides the paint event, but it calls the original method before drawing the text.
Parameters:
eventpaint event parameters.
function showEvent
show event that overwrites the original QSlider show event to apply a custom style sheet before showing the slider.
Parameters:
eventshow event parameters.
The documentation for this class was generated from the following file src/widgets.h