开发者

Accept edited wigets with QDataWidgetMapper

I'm making a small application that represents a to-do list. The list is stored in a cusom model (derived from QAbstractItemModel) and is displayed in a QTableView.

I have also a custom widget (TaskDialog) that is used to browse and edit tasks from the list. The children of the TaskDialog are mapped to the model with a QDataWidgetMMapper. On the task dialog I have also buttons that allow browsing through all the tasks in my to-do list (QDataWidgetMapper::toPrevious() ...).

The problem is that if I'm editing a task in the TaskDialog (e.g. the tasks name) and then browse to another task, the new edited enty 开发者_StackOverflow社区isn't set in the model. But if I edit something in the TaskDialog, then first change the focus to an other child widget of the TaskDialog and then press one of the browsing button, than the changes are written to the model.

How can I achive that widgets that are in a editing mode are accepted and written to the model.

I also tried the example of QDataWidgetMapper from Nokia. There it works perfectly. But they use a QStandardItemModel.

Best regards Luke


I found a solution: The submit policy of the QDataWidgetMapper has to be set to QDataWidgetMapper::ManualSubmit. Then allways when I browse to a new item (i.e. one of the browse buttons is pressed) i submit the changes with QDataWidgetMapper::submit().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜