Inside the setModelData() method of QItemDelegate I need to reformat the edited text and refresh the table. Which methods are available to do this ?
Inside the setModelData() method of QItemDelegate I need to reformat the edited text and refresh the table. Which methods are available to do this ?
What model do you use? Changes to the model are done by setData() and it should emit dataChanged() signal to notify view about changes. So if you use your own custom model (derived from QAbstractItemModel) make sure you emit dataChanged(). If you use some QStandardItemModel then any change will emit dataChanged() signal so you don't need to do anything, and the view should be refreshed.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Model is a QSqlTableModel, maybe the changed signal is being emitted, but I don't know if my method is right.
Qt Code:
{ if (oldVal != newVal) { /* // This is wrong...edit has been destroyed by now. if ((newVal.left(2) == "04") || (newVal.left(1) == "1")) edit->setText(newVal.left(2)+"-"+newVal.mid(2,4)+"-"+newVal.mid(6,4)); else edit->setText("("+newVal.left(2)+")"+newVal.mid(2,4)+"-"+newVal.mid(6,4)); */ } }To copy to clipboard, switch view to plain text mode
I'm stripping away the inputMask characters and checking the first 1 or 2 digits to see which format to apply. I save the edited digits in the model but I want the formatted text displayed (e.g. 04-1234-5678)
Last edited by vieraci; 31st May 2009 at 16:34. Reason: updated contents
hmm I think I don't understand... You are saving 2 digits in the model but want to display 8 digits with dashes it those cells with 2 digits? so maybe store the whole string in model, or modify the painting in paint() method. Also I would rather use QValidator instead of inputMask.
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
No, I'm saving a phone number, can be between 6 to 10 digits. I'm stripping away the inputMask characters so I can see the left most 1 or 2 digits but I'm saving just the digits.
That was my mistake. I have to save the whole string.
Hi,
you have to reimplement the data method for the DisplayRole in order to format "as you want" the saved data. Now, the data method of model is replying with the saved data without the two digits of masks. I think that this is the best way to manage the situation instead reimplementing the paint method.
Bye.
Alessandro
Bookmarks