Results 1 to 3 of 3

Thread: QTableView versus QTableWidget

  1. #1
    Join Date
    Jan 2006
    Posts
    73
    Thanks
    16
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableView versus QTableWidget

    Hello,
    I need to develop a spreadsheet widget with sorting capabilities on columns, where the presentation of the data inside each cell would depend on the type of data, and I would like to do some operations on a selection of cells (calculate the sum of the cells' values for instance).
    QTableWidget sounds a good option but the the Model/View Programming documentaiton warns against:
    "A number of convenience classes are derived from the standard view classes for the benefit of applications that rely on Qt's item-based item view and table classes. They are not intended to be subclassed, but simply exist to provide a familiar interface to the equivalent classes in Qt 3. Examples of such classes include QListWidget, QTreeWidget, and QTableWidget; these provide similar behavior to the QListBox, QListView, and QTable classes in Qt 3.
    These classes are less flexible than the view classes, and cannot be used with arbitrary models. We recommend that you use a model/view approach to handling data in item views unless you strongly need an item-based set of classes. " Pretty strong words!
    Using the QTableView road, I used the QSortFilterProxyModel to sort the columns and it works fine. How should I go with the presentation of the cell's content (an equivalent to QTableWidgetItem would be nice) and what about the handling of selection (somethings like QTableWidgetSelectionRange would help)?
    Many thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView versus QTableWidget

    You have to implement your own model for that (derived from QAbstractTableModel) or at least use QStandardItemModel.

  3. #3
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView versus QTableWidget

    You definatly want the Model-View classes. You will implement the following:

    QAbstractItemModel which will interface with your own data structures. This will contain only data. If you need only lightweight data then the QStandarditemModel might just work. That has internal data stuctures to hold data.

    QAbstractItemDelegate. This is where you can define drawing and editing for each cell

    The above is analagous to the old TableItem where data, drawing and editing were stuffed into one class.

    You will use
    QTableView
    QItemSelectionModel for handle selections.

    --Justin

  4. The following user says thank you to Glitch for this useful post:

    jcr (24th May 2006)

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. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 18:13
  3. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 14:49
  4. Replies: 6
    Last Post: 5th March 2006, 22:05
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 23:34

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.