Course Content
Python PySide6
About Lesson

In this lesson we want to learn about Python PySide6 Scrollbar & Slider, so first of all let’s talk about PySide6 Scrollbar & Slider.

 

Scrollbar Widget

Scrollbar is graphical element that appears on the side of widget such as a list, text box or  canvas. it allows users to scroll through the contents of widget such as list, text or canvas.

PySide6 Scrollbar widget is an easy to use element that provides developers with  straightforward way to create scrollbars for their applications. Here is an example of how to create a scrollbar using PySide6:

In above example we have created PySide6 application and QMainWindow object. after that we have created QScrollBar object and set its position and size. at the end we set the application’s geometry and window title and display the window.

 

 

Run the complete code and this will be the result.

Python PySide6 Scrollbar & Slider
Python PySide6 Scrollbar & Slider

 

 

 

Slider Widget

Slider widget is another graphical element that allows users to input value by dragging slider with the mouse. PySide6 library provides developers with simple way to create sliders for their applications. this is an example of how to create slider using PySide6:

In above example we have created new PySide6 application and also QMainWindow object. after that we have created QSlider object, set its orientation to horizontal, position and size. also we have set the initial value of the slider to 50. and at the end we set the application’s geometry and window title and display the window.

 

 

Run the complete code and this will be the result.

Python PySide6 Scrollbar & Slider
Python PySide6 Scrollbar & Slider

 

 

Now let’s create another example on QSlider and QScrollbar, this time we want to use Signals and Slots functionalities, Signals and slots are fundamental part of PySide6’s event driven programming model and they allow us to create responsive and interactive applications. this is an example of how to use signals and slots with slider and scrollbar widgets in PySide6:

In above example we have created new PySide6 application and also QMainWindow object. after that we have created QScrollBar object and QSlider object and set their position and size. also we have created QLabel object to display the value of the slider, and QVBoxLayout object to hold the widgets. at the end we connect the valueChanged signals of the scrollbar and slider to the update_label slot, which updates the label with the value of the scrollbar or slider.

When you run the example, you should see window containing scrollbar, slider and label displaying the value of the slider. when you move the scrollbar or slider, the label should update with the new value. This is possible thanks to the signals and slots mechanism provided by PySide6, which allows us to create interactive and responsive applications with ease.

 

 

Run the complete code and this will be the result.

Python PySide6 Scrollbar & Slider
Python PySide6 Scrollbar & Slider