Results 1 to 6 of 6

Thread: How to know when a cell in a QTableWidget has been edited

  1. #1
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to know when a cell in a QTableWidget has been edited

    I'm trying to port a QTable to QTableWidget.

    There's something that's killing me:

    How can I know when a cell has just been edited by the user?

    The signal itemChanged(QTableWidgetItem * item) is emited even when I change a cell with setItem, and that's not what I want.

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know when a cell in a QTableWidget has been edited

    What do you mean by edited ?

    -> Internal Value changed by double-clicking on the item ?

    If that's the case, you may have to catch an itemDoubleClicked() signal, followed by an itemChanged()...

  3. #3
    Join Date
    Mar 2007
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to know when a cell in a QTableWidget has been edited

    I mean when the user has just finished of typing something on a cell.

    I'm using currently the signal itemChanged() but that's emitted too when I change the text of a cell with setItem. So when I first add the data to the table, a function which makes some checks is called a lot of times unnecessary.

    I even experimented with delegates. I almost got it. I created my own delegate, I wanted to send a signal from setModelData(), but for some reason it doesn't allow me to send a signal from that function

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to know when a cell in a QTableWidget has been edited

    J-P Nurmi

  5. #5
    Join Date
    Jul 2007
    Location
    Cluj Napoca, Romania
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to know when a cell in a QTableWidget has been edited

    I once wrote a function that will tell me if a cell of QTableWidget is currently being edited by the user.

    Qt Code:
    1. bool CQTableWidget::isBeingEdited()
    2. {
    3. if(this->state()==QAbstractItemView::EditingState)
    4. return 1;
    5. else return 0;
    6. };
    To copy to clipboard, switch view to plain text mode 

    I needed to subclass QTableWidget though because state() is protected but you could use friend classes.
    But this won't tell you which cell is being edited .
    Hope it helps you.
    Cheers.
    Last edited by balazsbela; 12th July 2007 at 14:41.
    May the source be with you!

  6. #6
    Join Date
    Oct 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to know when a cell in a QTableWidget has been edited

    Hi! I know it's a little latte but for someone who have the same problem the solution is: when you invoke method setItem for QTableWidget you need to block signals and make changes with setItem afet that need to invoke one more time blockSignals with false argument and that's it.
    Now the slot for itemChanged will work normal when you will edit data in table.

Similar Threads

  1. repaint a cell or row in QTableWidget
    By alphaqt in forum Newbie
    Replies: 6
    Last Post: 26th June 2012, 11:21
  2. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 14:47
  3. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 03:57
  4. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 14:11
  5. Replies: 3
    Last Post: 8th September 2006, 18:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.