import sys from PyQt5.QtWidgets import QWidget,QApplication,QVBoxLayout,QLabel,QSlider from PyQt5.QtCore import Qt from PyQt5.QtGui import QFont class sliderDemo(QWidget): def __init__(self): super(sliderDemo, self).__init__() #label self.label = QLabel() self.label.setText("PyQt5") self.label.setAlignment(Qt.AlignCenter) #print(self.label.size()) #slider self.slider =QSlider(Qt.Horizontal) self.slider.setMaximum(100) #设置滑条最大刻度值为100 self.slider.setMinimum(1) #设置滑条最小刻度为1 self.slider.setSingleStep(1) #设置滑条步长 1 self.slider.setValue(10) #设置滑条当前值为10 self.slider.setTickPosition(QSlider.TicksAbove) #设置刻度在滑条的上方 self.slider.setTickInterval(1) #设置刻度步长为1 #信号与槽 self.slider.valueChanged.connect(self.sliderValueChangeHandle) #布局 vboxlayout = QVBoxLayout() vboxlayout.addWidget(self.label) vboxlayout.addWidget(self.slider) self.setLayout(vboxlayout) self.setWindowTitle("sliderDemo") self.resize(300,200) def sliderValueChangeHandle(self): print("slider current value:{}".format(self.slider.value())) #fontsize = self.slider.value() #self.label.setFont(QFont=fontsize) if __name__ == '__main__': app = QApplication(sys.argv) slider = sliderDemo() slider.show() sys.exit(app.exec_()) 参考:PyQt5基本控件详解之QSlider(十一)_jia666666的博客-CSDN博客_pyqt5 qslider
PyQt5之QSlider(十一)
最新推荐文章于 2023-05-11 22:24:34 发布