Answer the question
In order to leave comments, you need to log in
QModelDelegate: why table and delegate have different precision and locale?
Here's the code.
void CoeffDelegate::setEditorData(
QWidget* editor,
const QModelIndex & index) const
{
QLineEdit* currEdit = dynamic_cast<QLineEdit*>(editor);
QString text = index.model()->data(index).toString();
currEdit->setText(text);
}
model()->data
is known to produce a QVariant; I make it from float. There are two problems. Answer the question
In order to leave comments, you need to log in
Overriding QStyledItemDelegate. It has a function displayText
that turns the value into text. You can redefine it (I don't really like what I originally liked, several million are already 5.67e + 6), but that's not the point.
QWidget* LineEditDelegate::createEditor(
QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex&) const
{
QLineEdit* edit = new QLineEdit(parent);
edit->setLocale(option.locale); // важно! — локаль потом потребуется
return edit;
}
void LineEditDelegate::setEditorData(
QWidget* editor,
const QModelIndex & index) const
{
QLineEdit* currEdit = dynamic_cast(editor);
QVariant var = index.model()->data(index);
QString text = displayText(var, editor->locale());
currEdit->setText(text);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question