Results 1 to 4 of 4

Thread: QTableView delegate

  1. #1
    Join Date
    Dec 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default QTableView delegate

    Hi,
    I have a column of date in a TableView.
    I'd like to display a string ('futur') for a particular Date value (01/01/3000 for example).
    I have a look on QItemDelegate, I can change the text color for this special date but not the "displayed string".

    Thank's for your advices...

    Jef

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

    Default Re: QTableView delegate

    I think you have more or less three options:

    1) in your model return that string from data() instead of the date when Qt::DisplayRole is requested

    2) use a QIdentityProxyModel in between the model and the view that does that

    3) provide a custom delegate that displays the value differently. Easiest way for that is probably to derive from QStyledItemDelegate and override the displayText() method

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView delegate

    Thanks for your quick reply,
    I'll try your solutions and I'll tell you the result.

  4. #4
    Join Date
    Dec 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTableView delegate

    Hi,
    I have subclassed QStyledItemDelegate and override the displayText() as you propose and it works.
    Thanks again


    Qt Code:
    1. // replace the date 01/01/3000 by "permanent"
    2.  
    3. #include "permanentdelegate.h"
    4.  
    5. QString PermanentDelegate::displayText(const QVariant &value, const QLocale &locale) const
    6. {
    7. if (value.toDate() == QDate(3000,1,1)) {
    8. return QStyledItemDelegate::displayText("permanent", locale);
    9. }
    10. else
    11. return QStyledItemDelegate::displayText(value, locale);
    12. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to do QChartView delegate like QTableView item delegate
    By malleeswarareddy.s in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2015, 11:37
  2. QCombobox as QTableView delegate
    By martonmiklos in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2010, 15:23
  3. QTableView doesn't use delegate
    By treaves in forum Qt Programming
    Replies: 3
    Last Post: 1st February 2010, 09:45
  4. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  5. QTableView Delegate Usage
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2008, 07:03

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.