123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "MatrixTableItemDelegate.h"
- #include <QHBoxLayout>
- #include <QLabel>
- #include <QPushButton>
- #include <QButtonGroup>
- #include <QDebug>
- 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<void (QButtonGroup::*)(QAbstractButton *)>(&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
- {
- }
|