LineEditDelegate
::LineEditDelegate(QObject *parent, Myclass
* mc
){
}
{
connect(editor, SIGNAL(returnPressed()), m_mc, SLOT(getValue() ) );
//connect(editor, SIGNAL(textChanged(QString)), editor, SLOT(setText(QString)) );
return editor;
}
void LineEditDelegate
::setEditorData(QWidget *editor,
{
QString value
= index.
model()->data
(index, Qt
::EditRole).
toString();
QLineEdit *lineEdit
= static_cast<QLineEdit
*>
(editor
);
lineEdit->setText(value);
}
{
QLineEdit *lineEdit
= static_cast<QLineEdit
*>
(editor
);
double value = lineEdit->text().toDouble();
model->setData(index, value, Qt::EditRole);
}
void LineEditDelegate
::updateEditorGeometry(QWidget *editor,
{
editor->setGeometry(option.rect);
}
LineEditDelegate::LineEditDelegate(QObject *parent, Myclass* mc)
: QItemDelegate(parent), m_mc(mc)
{
}
QWidget *LineEditDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QLineEdit *editor = new QLineEdit(parent);
connect(editor, SIGNAL(returnPressed()), m_mc, SLOT(getValue() ) );
//connect(editor, SIGNAL(textChanged(QString)), editor, SLOT(setText(QString)) );
return editor;
}
void LineEditDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QString value = index.model()->data(index, Qt::EditRole).toString();
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
lineEdit->setText(value);
}
void LineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
double value = lineEdit->text().toDouble();
model->setData(index, value, Qt::EditRole);
}
void LineEditDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
To copy to clipboard, switch view to plain text mode
void getValue(){
double size = m_view->model()->data(index, Qt::DisplayRole).toDouble();
//The size is ALWAYS the older value, not the last one
}
void getValue(){
QModelIndex index = m_view->currentIndex();
double size = m_view->model()->data(index, Qt::DisplayRole).toDouble();
//The size is ALWAYS the older value, not the last one
QMessageBox::information(0, "value", QString("%1").arg(size));
}
To copy to clipboard, switch view to plain text mode
Bookmarks