QListView& QStandardItemModel在编辑行之前检查文本 [英] QListView & QStandardItemModel check text before editing row

查看:1130
本文介绍了QListView& QStandardItemModel在编辑行之前检查文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户编辑之前检查 QListView 中的一行的文本。如果它不适合一个模式,我不想接受它。



目前我有一个 QListView QStandardItemModel 。我可以通过 QStandardItemModel 轻松添加和删除项目。我还设置了列表视图的模型。



是否有一些代表事件

解决方案

您可以重载<$列表或模型上的 QStandardItemModel 的c $ c> data()和 setData()用户尝试编辑项目,您的 setData 将使用 Qt :: EditRole 调用,您可以进行处理。 / p>

http ://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#setData


I want to check the text of a row in QListView before the user is editing it. If it doesn't fit a pattern, I don't want to accept it.

Currently I have a QListView and QStandardItemModel. I can easily add and remove items via the QStandardItemModel. I also set the model of the list view.

Are there some delegates or event function(s) on the list or the model for editing?

解决方案

you can overload data() and setData() functions from QStandardItemModel, then when user tries to edit item your setData will be called with Qt::EditRole and there you can do your processing.

http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#setData

这篇关于QListView&amp; QStandardItemModel在编辑行之前检查文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆