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. Editing data in QStyledItemDelegate using QTextEditor

Editing data in QStyledItemDelegate using QTextEditor

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 660 Views
  • 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

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

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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