Trying to change spinboxdelegate example from spinbox to QTextEdit but it dosn't show

  • Hi
    im tring to find out why i can't see QTextEdit in item delegate , in my application so i remmbered 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 modifyed code:
    @QWidget *SpinBoxDelegate::createEditor(QWidget parent,
    const QStyleOptionViewItem &/
    option /,
    const QModelIndex &/
    index */) const
    //QSpinBox *editor = new QSpinBox(parent);
    QTextEdit *editor = new QTextEdit(parent);
    //editor->setGeometry(QRect(40, 30, 401, 31));
    editor->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
    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);

    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);
    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

  • The code looks ok at a first sight. Did you try to run a debugger? Put some qDebug() message into the methods. Did you forget to set the delegate on the view?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.