#include "floatspindelegate.h" #include <QDoubleSpinBox> QWFloatSpinDelegate::QWFloatSpinDelegate(QObject *editor = new QDoubleSpinBox(parent); editor->setFrame(false); editor->setMinimum(0); editor QModelIndex &index) const { float value = index.model()->data(index, Qt::EditRole).toFloat(); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->setValue(value); } // https://www.cnblogs.com *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->interpretText(); float value = spinBox
QSpinBox类和QDoubleSpinBox类均派生自QAbstractSpinBox类。 QSpinBox用于处理整数值,QDoubleSpinBox则用于处理浮点值,它们之间的区别就是处理数据的类型不同,其他功能都基本相同。 QDoubleSpinBox的默认精度是两位小数,但可以通过setDecimals()来改变。
#include "floatspindelegate.h"#include <QDoubleSpinBox>QWFloatSpinDelegate::QWFloatSpinDelegate(QObject *editor = new QDoubleSpinBox(parent); editor->setFrame(false); editor->setMinimum(0); editor QModelIndex &index) const{ float value = index.model()->data(index, Qt::EditRole).toFloat(); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->setValue(value);}// https://www.cnblogs.com *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->interpretText(); float value = spinBox
*editor = new QDoubleSpinBox(parent); editor->setFrame(false); editor->setMinimum(0); editor QModelIndex &index) const{ float value = index.model()->data(index, Qt::EditRole).toFloat(); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->setValue(value);}void QWFloatSpinDelegate ::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const{ QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->interpretText(); float value = spinBox
示例代码from PySide6.QtWidgets import QApplication, QDoubleSpinBox, QMainWindow, QSpinBox, QVBoxLayout, QWidgetdef spin_box_text_changed) my_spin_box.valueChanged.connect(spin_box_value_changed) my_double_spin_box = QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox
hs_conf") self.hs_conf.valueChanged.connect(self.conf_change) self.dsb_conf = QtWidgets.QDoubleSpinBox ) self.dsb_conf.valueChanged.connect(self.dsb_conf_change) self.dsb_iou = QtWidgets.QDoubleSpinBox