Skip to content

Instantly share code, notes, and snippets.

@saleph
Created September 5, 2015 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saleph/d8aeabd2f22205cc0d1b to your computer and use it in GitHub Desktop.
Save saleph/d8aeabd2f22205cc0d1b to your computer and use it in GitHub Desktop.
[qt5] slider - volume contorl
import sys
from PyQt5.QtWidgets import (QWidget, QSlider,
QLabel, QApplication)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUi()
def initUi(self):
sld = QSlider(Qt.Horizontal, self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setGeometry(30, 40, 100, 30)
sld.valueChanged[int].connect(self.changeValue)
self.label = QLabel(self)
self.label.setPixmap(QPixmap('mute.png'))
self.label.setGeometry(160, 40, 80, 30)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QSlider')
self.show()
def changeValue(self, value):
if value == 0:
self.label.setPixmap(QPixmap('mute.png'))
elif value > 0 and value <=30:
self.label.setPixmap(QPixmap('min.png'))
elif value >30 and value <= 80:
self.label.setPixmap(QPixmap('mid.png'))
else:
self.label.setPixmap(QPixmap('max.png'))
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment