Results 1 to 3 of 3

Thread: Multiple table delegates or a single table delegate?

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb Multiple table delegates or a single table delegate?

    Hello All,

    I am currently working on a project in which i have to use QTableView multiple times in different windows. But delegates will be different for each tables.
    As i said delegates will be different for QTableView, i want to know the right way to do that.
    Should i integrate all delegates in a single .h and .cpp, or should i use different delegate class for each.

    I know the answer will be very easy for you, but i want to know your views on that.
    It will be very helpful to me for creating a better project and for my knowledge too.

    Thanks
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,969
    Thanks
    277
    Thanked 808 Times in 797 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Multiple table delegates or a single table delegate?

    Delegates are attached to a table view, not to the model.

    The QAbstractItemDelegate::createEditor() method supplies the QModelIndex as an argument. It will contain row and column (0,0) in both cases, but no information about which table is asking for the editor. So if you put all of the code for managing the editors into one class, you will have no way to determine which editor to create. Even if you use different editors for different rows or columns in the various view, your code still has no way to determine which table view is being edited, so you'll end up creating the wrong editors.

    If you are asking, should you put the code for all of the delegate classes into the same source files, the answer is no. That's just a bad coding practice. If you make a change to one delegate class, then every table view will class will have to recompile even if it doesn't use the delegate that was changed.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multiple table delegates or a single table delegate?

    If most of the views display most of the data in exactly the same way with a few exceptions then I would suggest a set of delegate classes (usually by data type) that you attach to the relevant columns (rows) of each view, e.g. ConditionallyColouredNumberDelegate on column zero in some views and AlwaysHotPinkDelegate in others.

Similar Threads

  1. example code of table view with a custom delegate?
    By Dreamerzz in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2011, 16:33
  2. How to paint a table from an item delegate?
    By frank100 in forum Qt Programming
    Replies: 5
    Last Post: 6th April 2011, 14:22
  3. multiple table in a single variable
    By sattu in forum Qt Programming
    Replies: 0
    Last Post: 1st March 2011, 11:01
  4. Delegates and Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2006, 19:47
  5. How can i set a delegate on header in table
    By ankurjain in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2006, 13:04

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.