Add 03-09-01-02

QDial-功能
This commit is contained in:
muzing 2022-07-26 08:19:44 +08:00
parent 67a53a7d70
commit d6f360f214

View File

@ -0,0 +1,60 @@
import sys
from PySide6 import QtCore, QtWidgets
"""
QDial 功能
旋钮控件提供了刻度是否环绕等功能
.setWrapping(on: bool) 设置是否开启环绕即不在下方留有缺口而最大值最小值位置紧贴
.wrapping() -> bool 获取是否开启了环绕
.setNotchesVisible(visible: bool) 设置刻度是否可见
.notchesVisible() -> bool 获取刻度是否可见
.setNotchTarget(target: float) 设置刻度间的间距单位为像素默认值3.7
.notchTarget() -> float 获取刻度间距
.notchSize() -> int 获取当前刻度尺寸
"""
class MyWidget(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle("空白测试模板")
self.resize(800, 600)
self.setup_ui()
self.test()
def setup_ui(self) -> None:
"""设置界面"""
self.dial = QtWidgets.QDial(self)
self.dial.move(200, 200)
info_label = QtWidgets.QLabel(self)
info_label.move(320, 230)
@QtCore.Slot(int)
def show_value(value: int):
info_label.setText(f"旋钮的值变成了{value}")
info_label.adjustSize()
self.dial.valueChanged.connect(show_value) # type: ignore
def test(self) -> None:
"""测试QDial功能"""
# 开启环绕
self.dial.setWrapping(True)
# 使刻度可见,并调整尺寸
self.dial.setNotchesVisible(True)
self.dial.setNotchTarget(10.8)
print(self.dial.notchSize()) # 获取当前刻度线尺寸
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyWidget()
window.show()
sys.exit(app.exec())