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. How to get cell contents prior to they are changed in QTableWidget?

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • CAD_codingC Offline
    CAD_codingC Offline
    CAD_coding
    wrote on last edited by
    #1

    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!

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

      Hi,

      Maybe use a custom QStyledItemDelegate and reimplement setModelData

      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
      0
      • CAD_codingC Offline
        CAD_codingC Offline
        CAD_coding
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved