Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

PyQt5 QSlider | Python

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Slider in PyQt5 is used to set a value with the help of an indicator which can move back and forth over a graphical slide or bar. Many times one needs to provide values which lie between a range and in such cases slider is very useful. QSlider is the class used to add slider in an application.


A window has a slider and a label(QSlider). The size of the text gets scaled in or out as one move the indicator of the slider.

from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.resize(550, 393)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.slider = QtWidgets.QSlider(self.centralwidget)
        self.slider.setGeometry(QtCore.QRect(190, 100, 160, 16))
        # After each value change, slot "scaletext" will get invoked.
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(230, 150, 301, 161))
        # set initial font size of label.
        self.font = QtGui.QFont()
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "QSlider"))
    def scaletext(self, value):
        # Change font size of label. Size value could 
        # be anything consistent with the dimension of label.
        self.font.setPointSize(7 + value//2)
if __name__ == "__main__"
    app = QtWidgets.QApplication(sys.argv) 
    MainWindow = QtWidgets.QMainWindow() 
    ui = Ui_MainWindow() 


My Personal Notes arrow_drop_up
Last Updated : 27 Sep, 2019
Like Article
Save Article
Similar Reads
Related Tutorials