Results 1 to 11 of 11

Thread: Large number of rows for QTableView and QAbstractTableModel

  1. #1
    Join Date
    Dec 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Large number of rows for QTableView and QAbstractTableModel

    I'm fairly new to Qt. Initially I was using QTableWidget with 10000 rows, and had a bunch of signal/slots per row, and the performance was terrible.

    But now, I have a QTableView working using a subclassed QAbstractTableModel. I'm looking at the documentation but am confused as to how the memory management works for large amounts of data.

    How are rows "de-allocated" and do I need to "disconnect" the signal/slots for scrolled-off rows to keep the total active signal/slots low?

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

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    The table view does not "allocated" for rows that are being displayed.
    It basically determines which rows need to be draw, draws the grid and then delegates drawing of the cells to its item delegates, passing info on the cell to the delegate as it goes through the visible cells.

    There are also no per-cell or per-row signals, just signals of the view which in turn contain information about the cell for which an even happened.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Okay, thanks. I plan on adding checkboxes in some columns which I essentially want to modify the sourcing database. After scrolling through my 10,000 rows, will performance not go down because I might have 4 x 10,000 signals I am connecting? I did get QTableWidget working, and after clicking a checkbox, it took a few seconds for the checkbox to respond.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Instead of checkboxes, make these columns user checkable by returning the respective flag from your model's flags() method and returning the on/off value for the CheckStateRole in data().

    Cheers,
    _

  5. #5
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    24
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    @anda_skoa, I have a similar situation with large datasets, but no check boxes, thankfully. Am I to infer based on your comment "no-per-row-signal" that QTableView is a good enough design for large datasets?

    Comment/additional question: To get started I have subclassed QAbstractTableModel, and was surprised to find the view asking for data() per row, per column. I was expecting the view to ask for data only of the visible rows. Clicking on a menu "Table1" invokes QTableView::show() - should I call something else?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    The view might ask for more data than it can show at the moment, but usually not much more.

    It should be able to handle really large datasets.

    If the table is part of a widget then you don't need to call show() at all, unless the parent had already been shown at the time the table get created.

    Cheers,
    _

  7. #7
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    24
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Ok, it makes sense that the view is asking for more data than it can show.

    You're absolutely right about not calling show(), but my table view is part of a QSplitter sharing space with other widgets, and so toggle it based on what is being browsed Tables or Other collections. Personally, I would like to use QGridLayout for multiple widgets, but I haven't yet figured out how to create the resizable "splitter handles" between the layouts.

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,718
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    QGridLayout is a layout engine that positions and sizes the widgets contained within it. It is not a QWidget-based class, and has no visual representation on-screen. Therefore, it doesn't support dynamic interactive resizablilty using handles.

    Personally, I would like to use QGridLayout for multiple widgets
    Not really sure what your goals are. Do you want a dynamically resizable grid where the widgets in the grid can be rezised like the rows and columns in a table, expanding to fill their new rectangles? You can do that with nested QSplitters (horizontal within vertical or vice-versa).

    You might find something in the inqlude archive that does this with a cleaner UI than bulky splitters.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #9
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    24
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Being new to Qt, I am sure I misunderstood the connection between layout and the widgets positioned within. Thanks for straightening me out (seriously, the forum/archive has been extremely helpful).

    I am already using QSplitter (including the nested ones), but don't know if I am using it effectively. Let's say we have a horizontal QSplitter with two widgets like [H1 | H2], where I want to use the space H2 for many widgets, but one at a time - could be a table or a small list of QLineEdits, but not both at the same time. I manage the state of H2 as (table->hide, lineEdits->show) or vice-versa. Don't know if there is a better way to do this, since there is no "removeWidget" method in QSplitter.

    Thanks also for point out inqlude!

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,718
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Don't know if there is a better way to do this
    Make H2 a QStackedWidget (or use QStackedLayout), where your table, set of line edits (as a compound widget), etc. are pages within the stack. QStackedWidget is probably more appropriate for what you want to do. The setCurrentIndex() method manages the hide / show state of the widgets in the stack.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  11. The following user says thank you to d_stranz for this useful post:

    NameRakes (28th December 2016)

  12. #11
    Join Date
    Dec 2016
    Location
    New England, US
    Posts
    24
    Thanks
    6
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Large number of rows for QTableView and QAbstractTableModel

    Much better now with QStackedWidget! Got rid of QGridLayout even though this is a prototype. Didn't try QStackedLayout since QSplitter doc says adding layouts is not allowed. Thanks a bunch.

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 02:49
  2. Replies: 5
    Last Post: 24th October 2011, 15:22
  3. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 17:31
  4. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 16:29
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 07:55

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.