[Qt-interest] QDate representation in QCombobox

Petric Frank pfrank at gmx.de
Thu Jul 22 04:42:47 CEST 2010


Hello,

i have a model (QSqlTableModel) set to an instance of QCombox (->setModel). 
This comboc box is configured to be not editable.
>From the model i select a column which represents a date and passed it to the 
combo box instance. I've verified that the data returned from the model is of 
type QVariant::Date.

For the QComboBox instance i set the delegate to my own one to so that i get 
my own representation of the date value.
This works well for the items in the drop-down list, but not for the one in 
the selected field.

Where i have to set the delegate to get my representation of the date in the 
selected field ?

Sample code:
---------------------------------- cut ------------------------------------
QSqlTableModel *model = new QSqlTableModel (this);
QComboBox combo;

....  (db connection and GUI setup)

combo.setModel (model);
combo.setModelColumn (column);
combo.setItemDelegate (new owndelegate (this)); 
---------------------------------- cut ------------------------------------

In my delegate (owndelegate) i overloaded the displayText method to (for 
example) place the year last.

I get in the field where the actual selected value is displayed (sample date 
21st March 2010):  "2010.03.21"  (<-- this is wrong)
If i open the drop-down list i see the date correctly displayed: "21.03.2010".

Please don't answer with "set the correct locale" - i want to do something to 
being covered by locales.

What i have missed ?

regards
  Petric




More information about the Qt-interest-old mailing list