Skip to content

Commit 75f523e

Browse files
committed
Add 03-10-02-01
QDoubleSpinBox-简介
1 parent 752b452 commit 75f523e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
3+
from PySide6 import QtWidgets
4+
5+
"""
6+
QDoubleSpinBox 浮点数值设定框
7+
8+
与QSpinBox控件非常相似,只是数据类型为double
9+
官方文档:https://doc.qt.io/qtforpython/PySide6/QtWidgets/QDoubleSpinBox.html
10+
继承自QAbstractSpinBox
11+
12+
各种属性、方法与QSpinBox几乎完全一致,请读者参考QSpinBox小节
13+
此处只列出QDoubleSpinBox特有的属性方法
14+
15+
可以设置小数位数,注意不要超过double数据类型自身限制决定的最大上限
16+
.setDecimals(prec: int)
17+
.decimals() -> int
18+
19+
"""
20+
21+
22+
class MyWidget(QtWidgets.QWidget):
23+
def __init__(self, *args, **kwargs):
24+
super().__init__(*args, **kwargs)
25+
self.setWindowTitle("QDoubleSpinBox")
26+
self.resize(800, 600)
27+
self.setup_ui()
28+
29+
def setup_ui(self) -> None:
30+
"""设置界面"""
31+
32+
d_spinbox = QtWidgets.QDoubleSpinBox(self)
33+
d_spinbox.move(200, 200)
34+
35+
d_spinbox.setDecimals(3) # 显示3位小数
36+
d_spinbox.valueChanged.connect(lambda val: print(f"值变成了{val}")) # type: ignore
37+
38+
39+
if __name__ == "__main__":
40+
app = QtWidgets.QApplication(sys.argv)
41+
window = MyWidget()
42+
window.show()
43+
sys.exit(app.exec())

0 commit comments

Comments
 (0)