Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to change spinboxdelegate example from spinbox to QTextEdit but it dosn't show
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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);
    //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);
    }@

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved