Results 1 to 5 of 5

Thread: QTableWidget: cellChanged returning all cells?

  1. #1
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QTableWidget: cellChanged returning all cells?

    Hi

    I have the following code for a tableWidget. When I change a cell in the table and the cellChanged signal is called I get all cells in the table 'signalled' and I only want the one that was changed. I need to know the row and column that was changed which is why I am using cellChanged().

    tableValueChanged outputs every row and column not just the changed one

    What am I doing wrong?

    Thanks in advance!


    Qt Code:
    1. int row, col;
    2.  
    3. for(row = 0; row < tableWidget->rowCount(); row++)
    4. {
    5.  
    6. for(col = 0; col < tableWidget->columnCount(); col++)
    7. {
    8. connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(tableValueChanged(int, int)));
    9. }
    10. }
    11.  
    12. void className::tableValueChanged(int row, int col)
    13. {
    14. qDebug("value changed row = %d, col = %d", row, col);
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by taraj; 18th October 2016 at 00:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget: cellChanged returning all cells?

    You only need to connect the signal once.

    Cheers,
    _

  3. #3
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget: cellChanged returning all cells?

    Thanks for the reply, I removed the 2 for loops so connect was only called once but still got the following for 3 rows and 11 columns??

    value changed row = 0, col = 1
    value changed row = 0, col = 2
    value changed row = 0, col = 3
    value changed row = 0, col = 4
    value changed row = 0, col = 5
    value changed row = 0, col = 6
    value changed row = 0, col = 8
    value changed row = 0, col = 10
    value changed row = 0, col = 11
    value changed row = 1, col = 1
    value changed row = 1, col = 2
    value changed row = 1, col = 3
    value changed row = 1, col = 4
    value changed row = 1, col = 5
    value changed row = 1, col = 6
    value changed row = 1, col = 8
    value changed row = 1, col = 10
    value changed row = 1, col = 11
    value changed row = 2, col = 1
    value changed row = 2, col = 2
    value changed row = 2, col = 3
    value changed row = 2, col = 4
    value changed row = 2, col = 5
    value changed row = 2, col = 6
    value changed row = 2, col = 8
    value changed row = 2, col = 10
    value changed row = 2, col = 11

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTableWidget: cellChanged returning all cells?

    The first observation is that there are no col == 0 calls, so it isn't every cell in the table.

    This is precisely what you might see if you connect the signal and then populate the table. Where is the table populated?

  5. #5
    Join Date
    Jun 2011
    Posts
    23
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget: cellChanged returning all cells?

    I understand, works perfectly now thank you!

Similar Threads

  1. How to display cut cells in QTableWidget
    By danblanks in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 21:42
  2. [How to ?] Writing QTableWidget cells.
    By Rewo in forum Newbie
    Replies: 6
    Last Post: 4th April 2010, 11:00
  3. Merging cells in QTableWidget
    By lyucs in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 19:15
  4. QTableWidget + cellChanged(...)
    By losiem in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2008, 08:02
  5. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19

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.