[Qt-interest] QDate representation in QCombobox

Stephen Kelly steveire at gmail.com
Fri Jul 23 12:26:14 CEST 2010


Petric Frank wrote:
>> I've attached the example I did write.
> 
> Thanks for your example. I will give it a try.

I presume that the data displayed in the 'unexpanded' combobox is just 
whatever is returned for the Qt::DisplayRole for the selected index, right?

Another solution would be to use a proxy model.

class DateFormattingProxyModel : public QSortFilterProxyModel
{
  Q_OBJECT
public:
  DateFormattingProxyModel ...;

  /* reimp */ QVariant data(const QModelIndex &index, int role)
  {
    if (role != Qt::DisplayRole)
      return QSortFilterProxyModel::data(index, role);

    const QDate date sourceModel()->data(mapToSource(index), 
role).value<QDate>();
    return date.toString("foo bar bat");
  }

};

All the best,

Steve.




More information about the Qt-interest-old mailing list