muzing a629cc92b8 Add 03-09-01-01
QAbstractSlider-简介
2022-07-24 21:21:09 +08:00

51 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import sys
from PySide6 import QtCore, QtWidgets
"""
QAbstractSlider 滑块类控件的基类
用户可以通过滑块来输入整形数据
官方文档https://doc.qt.io/qtforpython/PySide6/QtWidgets/QAbstractSlider.html
继承自QWidget
本身为抽象基类不能被实例化主要有QSlider滑块、QDial旋钮、QScrollBar滚动条三个子类
"""
class MyWidget(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle("QAbstractSlider")
self.resize(800, 600)
self.setup_ui()
def setup_ui(self) -> None:
"""设置界面"""
# 滑块
slider = QtWidgets.QSlider(self)
slider.move(200, 200)
# 旋钮
dial = QtWidgets.QDial(self)
dial.move(360, 200)
info_label = QtWidgets.QLabel(self)
info_label.move(240, 200)
@QtCore.Slot(int)
def test(value: int):
info_label.setText(f"滑块的值变成了{value}")
info_label.adjustSize()
# 连接信号与槽,显示用户通过滑块/旋钮输入的值
# slider.valueChanged.connect(test) # type: ignore
dial.valueChanged.connect(test) # type: ignore
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyWidget()
window.show()
sys.exit(app.exec())