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 939 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • CJhaC CJha

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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

      CJhaC 1 Reply Last reply
      2
      • JonBJ JonB

        @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

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on 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

        • Login

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