-
Notifications
You must be signed in to change notification settings - Fork 206
/
03-QAbstractSpinBox-对齐方式、周边框架、清空文本内容、按钮标识.py
55 lines (39 loc) · 1.48 KB
/
03-QAbstractSpinBox-对齐方式、周边框架、清空文本内容、按钮标识.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
from PyQt5.Qt import *
class MyASB(QAbstractSpinBox):
def __init__(self, parent, num: int = 0):
super().__init__(parent)
self.current_num = 0
self.lineEdit().setText(f"{num}")
def stepEnabled(self) -> "QAbstractSpinBox.StepEnabled":
return QAbstractSpinBox.StepUpEnabled | QAbstractSpinBox.StepDownEnabled
def stepBy(self, steps: int) -> None:
self.current_num = self.current_num + steps
self.lineEdit().setText(str(self.current_num))
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QAbstractSpinBox")
self.resize(500, 500)
self.move(450, 250)
self.setup_ui()
def setup_ui(self):
asb = MyASB(self)
asb.resize(120, 30)
asb.move(150, 100)
# -------对齐方式--------
asb.setAlignment(Qt.AlignHCenter) # 水平居中
# ------周边框架-------
print(asb.hasFrame()) # 默认有边框
asb.setFrame(False) # 手动删除边框
# -----清空内容------
asb.clear()
# -----按钮标识-----
asb.setButtonSymbols(QAbstractSpinBox.UpDownArrows) # 上下箭头(默认值)
# asb.setButtonSymbols(QAbstractSpinBox.PlusMinus) # 加号减号
# asb.setButtonSymbols(QAbstractSpinBox.NoButtons) # 无按钮
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())