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. QTableWidget editing started?
QtWS25 Last Chance

QTableWidget editing started?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtablewidget
3 Posts 2 Posters 936 Views
  • 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.
  • C Offline
    C Offline
    CJha
    wrote on 30 Mar 2023, 07:35 last edited by
    #1

    Hi, is there any signal to detect when a cell has begun editing its data in QTableWidget?
    I am using QTableWidget and assigning QTableWidgetItem to all its cells. There are multiple signals that QTableWidget provides to give me the state of its cells, e.g.

    cellActivated(int row, int column)
    cellChanged(int row, int column)
    cellClicked(int row, int column)
    cellDoubleClicked(int row, int column)
    cellEntered(int row, int column)
    cellPressed(int row, int column)
    currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
    

    None of these signals tells me if the cell is being edited. The user can begin editing by many different methods set by using EditTriggers, so I cannot depend on a single signal from the above list to be sure that the editing has begun. Is there any way to get the signal or make my own signal (e.g. cellEditingBegun(int row, int column)) to know when a cell is being edited? I (preferably) do not want to use any other class other than QTableWidget and QTableWidgetItem since these 2 classes are enough for what I am trying to get done.

    J 1 Reply Last reply 30 Mar 2023, 08:16
    0
    • C CJha
      30 Mar 2023, 07:35

      Hi, is there any signal to detect when a cell has begun editing its data in QTableWidget?
      I am using QTableWidget and assigning QTableWidgetItem to all its cells. There are multiple signals that QTableWidget provides to give me the state of its cells, e.g.

      cellActivated(int row, int column)
      cellChanged(int row, int column)
      cellClicked(int row, int column)
      cellDoubleClicked(int row, int column)
      cellEntered(int row, int column)
      cellPressed(int row, int column)
      currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
      

      None of these signals tells me if the cell is being edited. The user can begin editing by many different methods set by using EditTriggers, so I cannot depend on a single signal from the above list to be sure that the editing has begun. Is there any way to get the signal or make my own signal (e.g. cellEditingBegun(int row, int column)) to know when a cell is being edited? I (preferably) do not want to use any other class other than QTableWidget and QTableWidgetItem since these 2 classes are enough for what I am trying to get done.

      J Offline
      J Offline
      JonB
      wrote on 30 Mar 2023, 08:16 last edited by JonB
      #2

      @CJha
      void QAbstractItemView::edit(const QModelIndex &index) is a slot which is called to start editing. It's not marked virtual so I don't think you can override it.

      void QAbstractItemView::openPersistentEditor(const QModelIndex &index) is called to open the editor, but again it's not virtual.

      Editing is handled by a QAbstractItemDelegate. You could set your own via void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate). You could have that call the table widget's current one for all purposes for the implementation. QAbstractItemDelegate::createEditor() is the method called when starting to edit, and is virtual, so if you override this you will know when editing starts.

      That's what I know.

      UPDATE
      I just found QTableWidget: signal to detect start of cell edit. This confirms what I have written. The accepted solution says

      One way is to reimplement the edit method of the table-widget, and emit a custom signal:

      I had not spotted that there is another QAbstractItemView::edit() overload, bool QAbstractItemView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event), which is virtual so you can override it. However, it is protected, you would need to subclass your QTableWidget to override it. The item delegate approach can be used without having to subclass QTableWidget or QTableWidgetItem.

      Also looks like I and @VRonin responded similarly in this forum at https://forum.qt.io/topic/115066/qtablewidget-editing-signal

      C 1 Reply Last reply 30 Mar 2023, 08:26
      2
      • J JonB
        30 Mar 2023, 08:16

        @CJha
        void QAbstractItemView::edit(const QModelIndex &index) is a slot which is called to start editing. It's not marked virtual so I don't think you can override it.

        void QAbstractItemView::openPersistentEditor(const QModelIndex &index) is called to open the editor, but again it's not virtual.

        Editing is handled by a QAbstractItemDelegate. You could set your own via void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate). You could have that call the table widget's current one for all purposes for the implementation. QAbstractItemDelegate::createEditor() is the method called when starting to edit, and is virtual, so if you override this you will know when editing starts.

        That's what I know.

        UPDATE
        I just found QTableWidget: signal to detect start of cell edit. This confirms what I have written. The accepted solution says

        One way is to reimplement the edit method of the table-widget, and emit a custom signal:

        I had not spotted that there is another QAbstractItemView::edit() overload, bool QAbstractItemView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event), which is virtual so you can override it. However, it is protected, you would need to subclass your QTableWidget to override it. The item delegate approach can be used without having to subclass QTableWidget or QTableWidgetItem.

        Also looks like I and @VRonin responded similarly in this forum at https://forum.qt.io/topic/115066/qtablewidget-editing-signal

        C Offline
        C Offline
        CJha
        wrote on 30 Mar 2023, 08:26 last edited by
        #3

        @JonB Thanks for the link to the previous question, I somehow missed it while trying to look for an answer. I will try to implement one of the methods to get the editing started signal.

        1 Reply Last reply
        0

        3/3

        30 Mar 2023, 08:26

        • Login

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