View Full Version : QTableView delegate
Jef
24th November 2016, 14:25
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
anda_skoa
24th November 2016, 15:40
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,
_
Jef
26th November 2016, 12:05
Thanks for your quick reply,
I'll try your solutions and I'll tell you the result.
:D
Jef
28th November 2016, 07:48
Hi,
I have subclassed QStyledItemDelegate and override the displayText() as you propose and it works.
Thanks again
// replace the date 01/01/3000 by "permanent"
#include "permanentdelegate.h"
QString PermanentDelegate::displayText(const QVariant &value, const QLocale &locale) const
{
if (value.toDate() == QDate(3000,1,1)) {
return QStyledItemDelegate::displayText("permanent", locale);
}
else
return QStyledItemDelegate::displayText(value, locale);
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.