File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
03-QtWidgets-常用控件/10-SpinBox-数值设定框/03-QDoubleSpinBox-浮点数值设定框 Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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 ())
You can’t perform that action at this time.
0 commit comments