Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to do multiplication with two values results in one cell Qtablewidget PyQt5



  • Hello,

    I want to make a column 3 of a Qtablewidget as the result of the multiplicaion of 2 other columns: Column 1 X column 2, i want to be automatically in many lines.

    i found a some result in : https://forum.qt.io/topic/74193/qtablewidget-operations-over-columns.

    I need in Python not C++, if anyone can help me please.

    Thanks in advance.



  • @YassineKira
    Your question seems to have nothing to do with the question title of "multiple values". Unless you mean values which are the result of multiplication, which is a different thing!

    QTableWidget is a wrapper around QTableView. It has its own model built-in, but that is hidden from you so you cannot override anything in it. Consequently you will have to use setData() (or setItem()) to explicitly set the desired result in column #3, and if you allow editing of the other columns you will have to set a slot to recalculate whenever those change.

    If you change over to using a QTableView instead you can define your own model. And that way, with subclassing, you can override the data() method so that it always calculates the product, instead of having to call setData(). That's how I would do it.

    We expect people to implement the code for suggestions themselves, not to have to write lines of code for everyone's questions. Still less if you expect a Python sample only. That's what programming is about. If you want to follow the example in the reference you quoted just translate the few lines of C++ into Python, it;s not hard.


Log in to reply