How to get cell contents prior to they are changed in QTableWidget?



  • Hi,

    So suppose I have a QTableWidget with many cells. Consider a particular cell with value say "String1".
    Now the user double clicks & edits the value to say "String2".

    What I want is that QTableWidget should emit a SIGNAL when the user has successfully edited the cell & pass the previous value i.e. "String1" to the connected SLOT. Now let me add that I do not want the SIGNAL to be emitted if the cell is merely selected or double clicked, but only when it is edited.

    You may ask why I want this. This is because I am checking the new value "String2" for some conditions; if it is OK then I let "String2" remain in the cell, but if it does not satisfy my conditions then I want the cell to have "String1" instead.

    I have used QTableWidget a little too much in my whole program, so it might not be possible to use Model/View framework now.
    Any suggestion is welcome.
    Thanks!


  • Lifetime Qt Champion

    Hi,

    Maybe use a custom QStyledItemDelegate and reimplement setModelData



  • Hi SGaist,

    What you are suggesting is for QTableView (I think?) & I have used QTableWidget everywhere in my application. So it might be very difficult to shift to QTableView & may create bugs.

    Any way to get the desired results with QTableWidget?


  • Lifetime Qt Champion

    QTableWidget is a QTableView with an internal model, so AFAIK there's nothing that forbids you to use custom item delegates.

    You'll simply access the underlying model of QTableWidget.


Log in to reply
 

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