#include "tabledelegate.h"#include <QtGui>tableDelegate::tableDelegate(QObject *parent) : QItemDelegate(parent){}QWidget *tableDelegate::createEditor(QWidget *parent) const{ //if (index.column() != 4){} // for editing the year, return a spinbox with a range from -1000 to 2100. QSpinBox *sb = new QSpinBox(parent); sb->setFrame(false); sb->setMaximum(2100); sb->setMinimum(-1000); return sb;}
#ifndef BOOKDELEGATE_H#define BOOKDELEGATE_H#include <QModelIndex>#include <QPixmap>#include <QSize>#include <QSqlRelationalDelegate>class QPainter;class tableDelegate : public QItemDelegate //public QItemDelegate{public: tableDelegate(QObject *parent); QWidget *createEditor(QWidget *parent) const;//, const QStyleOptionViewItem &option, const QModelIndex &indexprivate:};#endif
void MainWindow::Edit(QTableWidgetItem *item){ qDebug("%d",item->column()); tableDelegate * editor=new tableDelegate(item->tableWidget());}
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;