Results 1 to 7 of 7

Thread: Where to use QTableView and QTableWidget

  1. #1
    Join Date
    Nov 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Where to use QTableView and QTableWidget

    I went through availed post related to this.
    Still I did not get much and get confused for this. Sometimes I feel better to use QTableWidget.

    So could please help me out in this by giving such generic reasons to use QTableView or QTableWidget.



    Thanks ...

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

    Default Re: Where to use QTableView and QTableWidget

    If your use case it better served with a QTableWidget, then by all means use a QTableWidget.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,309
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Where to use QTableView and QTableWidget

    Quote Originally Posted by psarangi View Post
    So could please help me out in this by giving such generic reasons to use QTableView or QTableWidget.
    The major difference between the two is that QTableView requires you to use an external class derived from QAbstractItemModel with it. The rowCount(), columnCount(), and data() methods for the item model are used by the table view to tell it how to fill in and format the table cells.

    In QTableWidget, the model is built-in and you simply set the count and contents of table rows and columns individually in your program by creating QTableWidgetItem instances, filling them with information, and inserting them into the table widget.

    If you are displaying information from a database, then QTableView is the way to go. If you are displaying data generated internally by your program, then either one will work, whichever is easier to map onto your program's data representation.

  4. #4
    Join Date
    Nov 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Where to use QTableView and QTableWidget

    Thnaks for your reply ..

    Yes i have a xml file, from which i need to get the data.
    So i should use QTableView rather than QTableWidget.


    Thanks ..

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Where to use QTableView and QTableWidget

    Quote Originally Posted by psarangi View Post
    Yes i have a xml file, from which i need to get the data.
    So i should use QTableView rather than QTableWidget.
    It mostly depends on the amount of data and whether you already have a model that interfaces with the data.

    Cheers,
    _

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,309
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Where to use QTableView and QTableWidget

    It mostly depends on the amount of data and whether you already have a model that interfaces with the data.
    It also depends on how the XML data is organized. If it is just a series of elements with attributes, all elements of the same type, then it will map easily to a table. You can choose to create a class based on QAbstractItemModel, read the XML into that, and put it in a QTableView. Or you can read the XML and dynamically insert QTableWidgetItem instances into a QTableWidget.

    If I was doing it, I would use the model / view approach because it makes a lot of things easier, like sorting or filtering the data for example. It is a lot harder to do that with QTableWidget.

    On the other hand, if the XML is hierarchical, where elements have sub-elements, and so forth, then it will be difficult to match this to a table and it would be more appropriate to display this as a tree that follows the hierarchy. Use a QTreeView or QTreeWidget in that case.

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

    psarangi (7th February 2014)

  8. #7
    Join Date
    Nov 2013
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Where to use QTableView and QTableWidget

    Thank you all

Similar Threads

  1. Replies: 1
    Last Post: 1st July 2011, 13:03
  2. Replies: 1
    Last Post: 26th November 2010, 12:06
  3. qtablewidget and qtableview
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2008, 16:01
  4. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 09:33
  5. QTableView versus QTableWidget
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 19:51

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
  •  
Qt is a trademark of The Qt Company.