Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Changing content of part of QTableWidget after editiong

    General and Desktop
    qtablewidget qitemdelegate qmodelidex
    4
    4
    1557
    Loading More Posts
    • 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.
    • M
      michelson last edited by michelson

      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.
      Eg,:
      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)

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Q
          qt_5.x last edited by

          help me
          link >>>
          https://forum.qt.io/topic/62102/help-webkit-help

          1 Reply Last reply Reply Quote -1
          • kshegunov
            kshegunov Moderators last edited by

            @michelson said:
            Hello,

            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:

            • Here is an overview of the model-view framework
            • A simple spinbox delegate example
            • Icons example that uses delagets

            I hope this helps.
            Kind regards.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post