QTimeEdit in the QTableView problem
-
Hi,
I have a problem with displaying time in the QTableView.
I want to display time in "mm:ss" format so I defined createEditor method in my delegate like thatQWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("mm:ss"); timeEdit->setAlignment(Qt::AlignCenter); return timeEdit; }
When I set a cell value say QTime(0,0,10) I see "00:00" in that cell,
after doubleclick "00:10" and when I defocused this cell I can see 00:00 again.
I checked data saving to model and they had proper value "00:00".Any suggestion?
Thanks in advance -
Hi,
I have a problem with displaying time in the QTableView.
I want to display time in "mm:ss" format so I defined createEditor method in my delegate like thatQWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("mm:ss"); timeEdit->setAlignment(Qt::AlignCenter); return timeEdit; }
When I set a cell value say QTime(0,0,10) I see "00:00" in that cell,
after doubleclick "00:10" and when I defocused this cell I can see 00:00 again.
I checked data saving to model and they had proper value "00:00".Any suggestion?
Thanks in advance@Milosz
Hi. I have to say I am confused by your description. Maybe somebody else will understand better.Can we start with one thing: are you aware that
createEditor()
is only called while a cell is being edited (e.g. double-click)? The rest of the time is just a non-widget delegate displaying the text of a time.The display of values, whether for edit or not, does not affect what value is in the model.
setEditorData()
andsetModelData()
transfer values between model and editor.I do not know what issue you are reporting where.
-
@Milosz
Hi. I have to say I am confused by your description. Maybe somebody else will understand better.Can we start with one thing: are you aware that
createEditor()
is only called while a cell is being edited (e.g. double-click)? The rest of the time is just a non-widget delegate displaying the text of a time.The display of values, whether for edit or not, does not affect what value is in the model.
setEditorData()
andsetModelData()
transfer values between model and editor.I do not know what issue you are reporting where.
-
@JonB
Thanks for the clarification.
I think you understood very good the problem.You pointed: " The rest of the time is just a non-widget delegate displaying the text of a time"
but I still have no idea how to magage the problemHi,
Implement the displayText method of your delegate to return what you want to show.
-
Hi,
Implement the displayText method of your delegate to return what you want to show.
-