Editing data in QStyledItemDelegate using QTextEditor



  • Hi,
    I use the following code to write the modified text back to the model and save the changes to the db:

    QTextEdit *tedit = qobject_cast<QTextEdit*>(editor);
                QModelIndex updateIndex(index.model ()->index(index.row (),0,index.parent ()));
    
                QString fixID;
                QVariant v(updateIndex.data (Qt::DisplayRole));
                fixID = v.toString ();
                qDebug() << "FixID: " << fixID;
    
                QModelIndex updateIndex2(index.model ()->index(index.row (),6,index.parent ()));
    
                QString descItem;
                QVariant desc(updateIndex2.data (Qt::DisplayRole));
                descItem = desc.toString ();
                qDebug() << "descItem: " << descItem;
    
                model->setData (index,tedit->setText(descItem));
                QVariant de(index.data (Qt::DisplayRole));
                QString fixedDescr;
                fixedDescr = de.toString ();
                fixquery.prepare ("UPDATE Items SET Color = :Color WHERE ID = :fixID ");
                fixquery.bindValue (":Color",fixedDescr);
                fixquery.bindValue (":fixID",fixID);
                fixquery.exec ();
    

    The model->setData (index,tedit->setText(descItem)); line generates an error message:
    C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:194: error: invalid use of void expression
    model->setData (index,tedit->setText(descItem));
    ^
    How can I fix that line to make it work? Thank you for your help.


  • Qt Champions 2016

    Hi
    In
    The model->setData (index,tedit->setText(descItem));
    You give it :
    tedit->setText(descItem)
    But that is a function call and it returns void.

    So something like this
    QString str = tedit->toPlainText();
    model->setData (index,str);



  • For anyone who got here googling: the above is not a nice example of how to use a delegate


Log in to reply
 

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