Results 1 to 3 of 3

Thread: PYQT5 QTableWidget Retrieving values from cells

  1. #1
    Join Date
    Jul 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: PYQT5 QTableWidget Retrieving values from cells

    I'm using PYQT5 and trying to loop though the rows in my table to retrieve the values in cells adding them to a list. Below is one of the many versions of the code I've written.

    Qt Code:
    1. def grouping(self):
    2. nrows = self.Table.rowCount()
    3. group = []
    4.  
    5. for row in range(0,nrows):
    6. item = self.Table.item(row, 2)
    7. item_text = item.text()
    8.  
    9. group.append(item)
    10.  
    11. print(group)
    To copy to clipboard, switch view to plain text mode 

    If I don't use the "item_text = item.text()" line my list only contains the qtablewidgetitem objects. If I try to use the "item_text = item.text()" line or even add ".text()" to the item= line I get an error saying "AttributeError: 'NoneType' object has no attribute 'text'". Any help would be greatly appreciated.


    Added after 13 minutes:


    I should have also mentioned I'm setting up the table using the setItem function. The items are numbers defaulted as 1, that the user can edit if they wish to regroup the rows.
    Last edited by trevor44; 28th July 2019 at 18:00.

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

    Default Re: PYQT5 QTableWidget Retrieving values from cells

    Are you sure you are getting valid table widget item objects back?

    The error sounds as if the item(row, column) function does not actually return anything, e.g. no such column or similar access error.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2019
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: PYQT5 QTableWidget Retrieving values from cells

    anda_skoa - I think you are correct. I believe I made an elementary mistake when setting up my loop now that I look back at my code in it entirety. I will take a closer look when I return home tonight. Thank you.

Similar Threads

  1. Replies: 2
    Last Post: 28th July 2019, 17:36
  2. [SOLVED] Retrieving data from QTableWidget
    By timmu in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2011, 11:36
  3. How to display cut cells in QTableWidget
    By danblanks in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 21:42
  4. read QTableWidget cells
    By navid in forum Newbie
    Replies: 8
    Last Post: 4th April 2010, 10:40
  5. Retrieving and converting values
    By jcoop in forum Newbie
    Replies: 3
    Last Post: 19th February 2009, 08:01

Tags for this Thread

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.