PDA

View Full Version : Trying to change spinboxdelegate example from spinbox to QTextEdit but it dosn’t show



umen
12th January 2012, 09:50
Hi
im trying to find out why i can’t see QTextEdit in item delegate , in my application so i remembered there is simple example in the examples
i did put simple QTextEdit in the sample code and it also didn’t show the QTextEdit why ? what im doing wrong
here is the modified code:


QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
//QSpinBox *editor = new QSpinBox(parent);
//editor->setMinimum(0);
//editor->setMaximum(100);
QTextEdit *editor = new QTextEdit(parent);
//editor->setGeometry(QRect(40, 30, 401, 31));
editor->setLayoutDirection(Qt::LeftToRight);
editor->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
editor->setFrameShape(QFrame::WinPanel);
editor->setLineWidth(0);
editor->setReadOnly(true);
editor->setText("This is text test!!1");
return editor;
}
//! [1]

//! [2]
void SpinBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
/* int value = index.model()->data(index, Qt::EditRole).toInt();

QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);*/
QTextEdit *textEdit = static_cast<QTextEdit*>(editor);
textEdit->setText("This is text test!!1");


}
//! [2]

//! [3]
void SpinBoxDelegate::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);*/

QTextEdit *textEdit = static_cast<QTextEdit*>(editor);
}
//! [3]

//! [4]
void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}

wysota
12th January 2012, 12:38
So what does it show when you enter edit mode?