oubleSpinBox 显示值不正确
oubleSpinBox Displayed value not correct
我有一个像这样的旋转框:
input = QDoubleSpinBox()
input.value = 0.02
在gui中显示:
2.00
但我喜欢它显示的内容
0.02
我该怎么办?
如果你喜欢它显示0.02
您可能需要以小数位设置步骤的精度
例如:setSingleStep (0.02)
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QLabel,
QVBoxLayout, QDoubleSpinBox)
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.initWindow()
def initWindow(self):
vBoxLayout = QVBoxLayout()
self.label = QLabel("Current Value", self)
self.label.move(60, 60)
vBoxLayout.addWidget(self.label)
self.spinBox = QDoubleSpinBox(self)
self.spinBox.move(60, 30)
self.spinBox.setMinimum(0)
self.spinBox.setMaximum(12)
self.spinBox.setSingleStep(0.02)
self.spinBox.valueChanged.connect(self.valueChanged)
def valueChanged(self):
self.label.setText("Current Value {:.2f}".format(self.spinBox.value()))
if __name__ == '__main__':
aplicacion = QApplication(sys.argv)
window = Window()
window.setGeometry(100, 100, 220, 100)
window.show()
sys.exit(aplicacion.exec_())
我有一个像这样的旋转框:
input = QDoubleSpinBox()
input.value = 0.02
在gui中显示:
2.00
但我喜欢它显示的内容
0.02
我该怎么办?
如果你喜欢它显示0.02
您可能需要以小数位设置步骤的精度
例如:setSingleStep (0.02)
import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QLabel,
QVBoxLayout, QDoubleSpinBox)
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.initWindow()
def initWindow(self):
vBoxLayout = QVBoxLayout()
self.label = QLabel("Current Value", self)
self.label.move(60, 60)
vBoxLayout.addWidget(self.label)
self.spinBox = QDoubleSpinBox(self)
self.spinBox.move(60, 30)
self.spinBox.setMinimum(0)
self.spinBox.setMaximum(12)
self.spinBox.setSingleStep(0.02)
self.spinBox.valueChanged.connect(self.valueChanged)
def valueChanged(self):
self.label.setText("Current Value {:.2f}".format(self.spinBox.value()))
if __name__ == '__main__':
aplicacion = QApplication(sys.argv)
window = Window()
window.setGeometry(100, 100, 220, 100)
window.show()
sys.exit(aplicacion.exec_())