Skip to content

Class QSliderLabeled

ClassList > 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 = 8
Maximum number of labels to display.
int m_sliderSpread = 48
Size 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.

void QSliderLabeled::ApplyStyleSheet () 


function QSliderLabeled

Constructor of the labeled QSlider.

explicit QSliderLabeled::QSliderLabeled (
    QWidget * parent=nullptr
) 

Parameters:

  • parent parent class.

function SetDisplayLabels

Toggles the display of text labels on the slider.

inline void QSliderLabeled::SetDisplayLabels (
    const bool value
) 

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:

  • value true to enable the display of labels, false to disable them.

function SetGrooveMargin

Sets the margin of the groove of the slider.

inline void QSliderLabeled::SetGrooveMargin (
    const int value
) 

Parameters:

  • value

function SetLabelInterval

Sets the interval for displaying labels on the slider.

inline void QSliderLabeled::SetLabelInterval (
    const int value
) 

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:

  • value The interval value specifying the spacing between labels. Must be a positive integer.

function SetMaxNumberOfLabels

Sets Maximum number of labels to display in the slider.

inline void QSliderLabeled::SetMaxNumberOfLabels (
    const int value
) 

Parameters:

  • value maximum 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.

inline void QSliderLabeled::SetSliderSpread (
    const int value
) 

Parameters:

  • value the slider spread.

Protected Attributes Documentation

variable m_grooveMargin

int QSliderLabeled::m_grooveMargin;

Slider groove margin.


variable m_labelInterval

Interval between labels displayed on a slider.

int QSliderLabeled::m_labelInterval;

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.

int QSliderLabeled::m_maxNumberOfLabels;


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.

int QSliderLabeled::m_sliderSpread;


Protected Functions Documentation

function event

Overrides the event() method from the parent class.

inline bool QSliderLabeled::event (
    QEvent * e
) override

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:

  • e The event object.

Returns:

True if the event was handled, false otherwise.


function mouseMoveEvent

Triggered when the mouse is moved over the labeled QSlider.

void QSliderLabeled::mouseMoveEvent (
    QMouseEvent * event
) override

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:

  • event A pointer to the QMouseEvent that 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.

void QSliderLabeled::paintEvent (
    QPaintEvent * event
) override

Parameters:

  • event paint event parameters.

function showEvent

show event that overwrites the original QSlider show event to apply a custom style sheet before showing the slider.

inline void QSliderLabeled::showEvent (
    QShowEvent * event
) override

Parameters:

  • event show event parameters.


The documentation for this class was generated from the following file src/widgets.h