PyQt Basic Widgets PyQt QSlider Widget & Signal - PyQt

What is PyQt QSlider Widget & Signal?

QSlider class object presents the user with a groove over which a manage may be moved. it is a classic widget to control a bounded cost. role of the manage at the groove is equal to an integer between the decrease and the higher bounds of the manage.

A slider manage may be displayed in horizontal or vertical manner by using mentioning the orientation in the constructor.

The following table lists some of the frequently used methods of QSlider class −

Given below are the most commonly used methods of QSlider.

S.No.

Methods & Description

1

setMinimum()

Sets the lower bound of the slider

2

setMaximum()

Sets the upper bound of the slider

3

setSingleStep()

Sets the increment/decrement step

4

setValue()

Sets the value of the control programmatically

5

value()

Returns the current value

6

setTickInterval()

Puts the number of ticks on the groove

7

setTickPosition()

Places the ticks on the groove. Values are −

QSlider.NoTicks

No tick marks

QSlider.TicksBothSides

Tick marks on both sides

QSlider.TicksAbove

Tick marks above the slider

QSlider.TicksBelow

Tick marks below the slider

QSlider.TicksLeft

Tick marks to the left of the slider

QSlider.TicksRight

Tick marks to the right of the slider

QSlider Signals

S.No.

Methods & Description

1

valueChanged()

When the slider's value has changed

2

sliderPressed()

When the user starts to drag the slider

3

sliderMoved()

When the user drags the slider

4

sliderReleased()

When the user releases the slider

valueChanged() signal is the one which is most frequently used.

Example

The following example demonstrates the above functionality. A Label and a horizontal slider is placed in a vertical format. Slider’s valueChanged() signal is attached to valuechange() technique.

The slot feature valuechange() reads current value of the slider and makes use of it as the size of font for label’s caption.

The complete code is as follows −

The above code produces the following output −

PyQt - QSlider Widget & Signal

The font length of the label changes as handle of the slider is moved across the handle.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PyQt Topics