#include "MatrixTableItemDelegate.h" #include #include #include #include #include SchemeBar::SchemeBar(const QString &lLabel, const QString &rLabel, const QStringList &vlist, QWidget *parent) : QDialog(parent), leftLabel(lLabel), rightLabel(rLabel), barValueList(vlist) { setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); QHBoxLayout *hlay = new QHBoxLayout; QLabel *l = new QLabel(leftLabel); QLabel *r = new QLabel(rightLabel); QHBoxLayout *centerLay = new QHBoxLayout; QButtonGroup *btnGroup = new QButtonGroup(this); for (QString &v : barValueList) { QPushButton *btn = new QPushButton(v); centerLay->addWidget(btn); btnGroup->addButton(btn); if (v.startsWith("1/")) { btn->setText(v.split("/")[1]); } else { btn->setText(v); } btn->setProperty("number", v); } connect(btnGroup, static_cast(&QButtonGroup::buttonClicked), this, &SchemeBar::barClicked); hlay->addWidget(l); hlay->addLayout(centerLay); hlay->addWidget(r); setLayout(hlay); } void SchemeBar::barClicked(QAbstractButton *btn) { emit setValue(btn->property("number").toString()); this->close(); } MatrixTableItemDelegate::MatrixTableItemDelegate(QWidget *parent) : QStyledItemDelegate(parent) { } QWidget *MatrixTableItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStringList l = { "9", "7", "5", "3", "1", "0", "1", "3", "5", "7", "9" }; SchemeBar *scheme = new SchemeBar("左", "右", l, parent); return scheme; } void MatrixTableItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { } void MatrixTableItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { }