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. Display bulk data on QTableWidget
Qt 6.11 is out! See what's new in the release blog

Display bulk data on QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Piyush
    wrote on last edited by
    #1

    Hi,

    I need to display bulk data on QTableWidget, for which I need to show all the data at one go. Currently, I am running the following script which populates the data on QTableWidget in an item by item manner. I am using dataframe (python) to store data and showing it pushing data item by item on QtableWidget. This is how I am doing it right now:

                self.ui.out_table.setRowCount(df.shape[0])
                for row in range (0, df.shape[0]):
                    for col in range (0, len(df.columns) + 1):
                            data = str(final_data.iloc[row, col] )
                            self.ui.out_table.setItem(row, col, QTableWidgetItem(str(data)))
    

    Is there a way by which I can display the complete dataframe in one go?

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      QTableWidget is item based and you give it data by inserting items.
      Im not sure what you mean "in one go"
      There is no way around using items.

      You could use the View version and a custom model and store the data directly in model.
      http://doc.qt.io/qt-5/qabstracttablemodel.html

      Alternatively, if its just so data is shown at same time, you can use
      setUpdatesEnabled(bool)
      so it first draws when finished adding.

      1 Reply Last reply
      4
      • P Piyush

        Hi,

        I need to display bulk data on QTableWidget, for which I need to show all the data at one go. Currently, I am running the following script which populates the data on QTableWidget in an item by item manner. I am using dataframe (python) to store data and showing it pushing data item by item on QtableWidget. This is how I am doing it right now:

                    self.ui.out_table.setRowCount(df.shape[0])
                    for row in range (0, df.shape[0]):
                        for col in range (0, len(df.columns) + 1):
                                data = str(final_data.iloc[row, col] )
                                self.ui.out_table.setItem(row, col, QTableWidgetItem(str(data)))
        

        Is there a way by which I can display the complete dataframe in one go?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Piyush
        In addition to what @mrjj writes, note http://doc.qt.io/qt-5/qtablewidget.html#setItem:

        If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).

        1 Reply Last reply
        1

        • Login

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