void CadComissoes::getUsuarios()
{
OpenDB();
SQL = "SELECT COD_USER, NAME, COD_GROUP ";
SQL+= "FROM USERS";
qry.prepare(SQL);
qry.exec();
model->setQuery(qry);
ui.tableView_ComissaoUsuarios->setModel(model);
MyDelegate *iDelegate = new MyDelegate(this);
ui.tableView_ComissaoUsuarios->setItemDelegate(iDelegate);
CloseDB();
}
MyDelegate
::MyDelegate(QObject *parent
){
}
{
if (!index.isValid())
{
qDebug() << "Not Valid index";
}
if (index.column() == 2)
{
editor->setMinimum(0);
editor->setMaximum(100);
return editor;
}
}
{
int value = index.model()->data(index, Qt::DisplayRole).toInt();
QSpinBox *spinBox
= static_cast<QSpinBox
*>
(editor
);
spinBox->setValue(value);
}
{
QSpinBox *spinBox
= static_cast<QSpinBox
*>
(editor
);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value, Qt::EditRole);
}
void CadComissoes::getUsuarios()
{
OpenDB();
QSqlQuery qry;
QString SQL;
model = new QSqlQueryModel();
SQL = "SELECT COD_USER, NAME, COD_GROUP ";
SQL+= "FROM USERS";
qry.prepare(SQL);
qry.exec();
model->setQuery(qry);
ui.tableView_ComissaoUsuarios->setModel(model);
MyDelegate *iDelegate = new MyDelegate(this);
ui.tableView_ComissaoUsuarios->setItemDelegate(iDelegate);
CloseDB();
}
MyDelegate::MyDelegate(QObject *parent)
:QItemDelegate(parent)
{
}
QWidget *MyDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (!index.isValid())
{
qDebug() << "Not Valid index";
}
if (index.column() == 2)
{
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(0);
editor->setMaximum(100);
return editor;
}
}
void MyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
int value = index.model()->data(index, Qt::DisplayRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);
}
void MyDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
int value = spinBox->value();
model->setData(index, value, Qt::EditRole);
}
To copy to clipboard, switch view to plain text mode
Bookmarks