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. how to make the tablewidget cost less time?
Forum Updated to NodeBB v4.3 + New Features

how to make the tablewidget cost less time?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 469 Views 2 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.
  • nicker playerN Offline
    nicker playerN Offline
    nicker player
    wrote on last edited by
    #1

    here's the issue that I used the qtablewidget to show the data from the database.but I found that the creating the qtablewidget and tablewidgetitem part would cost nearlly 2 seconds ,in fact it only created 100 rows.how to make the code to save the time?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Use a custom model with a QTableView instead the convenience QTableWidget.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • nicker playerN Offline
        nicker playerN Offline
        nicker player
        wrote on last edited by
        #3

        is there any solutions that without using the tableview?cause that the project was highly related to the qtablewidget it is hard to replace by using the tableview object.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then it's going to be complicated.
          You should benchmark the code you use to create that table widget. There might be some stuff that could be optimized.
          In any case, if your application is that much dependent on QTableWidget, there might be some architectural consideration that should be addressed.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            For a QTableWidget you have to create the widget for every cell in the table view. This can take quite some time (depending on the number of rows and columns). The QTableView manages the individual widgets for the cells differently. Simply speaking, it just shows the widgets that are visible and reuses them when scrolling. This is why QTableView is the better choice for a lot of data.

            However, you are saying that you have only 100 rows. If it is only a hand full of columns 2 seconds might be a little long (though 100 rows by 10 columns would already be 1000 widgets). Do you have a single call to the database to fetch the data? Or are you querying one row at a time?

            1 Reply Last reply
            4

            • Login

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