Important: Please read the Qt Code of Conduct -

Changing content of part of QTableWidget after editiong

  • Hello guys,
    it problably due to my lack of understanding the Qt mechanism of Item-Model View i encountered a problem:
    lets say you have a 2-column QTableWidget (with custom QItemDelegate), second column depends of a choice in the first column.
    in first column you have combo box with either voltage or current as a choice so the sencond column will have values available either {1V, 3V, 5V} or {1A, 3A,7A}.
    When i change values in second column everything is ok since they are already set, however when i change the type in first column (eg.: voltage to currend) i want the value in the second column to change to the corresponding one (eg.: first column had 5V chosen so i want them to change to 7A).
    I assumed i had to reimplement QItemDelegate::setModelData(...) however i failed to achive above behaviour. Can you give me a sample or a link to a simple tutorial (i dont find Qt documentation helpfull, i mean descriptions are fine but the whole mechanism is not clear for me i guess)

  • Lifetime Qt Champion


    You should rather implement your own model based on QAbstractTableModel. That way you'll be able to handle your use case more easily.

    I'd recommend reading "C++ GUI Programming with Qt 4" from Jasmin Blanchette and Mark Summerfield referenced here. Even if it's for Qt 4, it's still valid and a very good book and covers custom models very well.

  • Qt Champions 2017

    @michelson said:

    I assumed i had to reimplement QItemDelegate::setModelData(...)

    I think this should suffice for your case. You can of course always create your own model as @SGaist suggested. As for your request for additional material:

    I hope this helps.
    Kind regards.