具有QStandardItemModel的QTableView:如何在编辑单元格期间执行实时更新? [英] QTableView with QStandardItemModel: How to perform live updates during editing a cell?

查看:854
本文介绍了具有QStandardItemModel的QTableView:如何在编辑单元格期间执行实时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我切换到了QT.这花了一些时间,但我开始找到解决方法.但是,仍然存在一个问题:

Recently, I made the switch to QT. It has taken some time, but I am starting to find my way around. However, one issue remains:

我想移植一个程序,该程序在编辑表视图(带有QStandardItemModel的QTableView)中的单元格时响应每次按键.这个想法是在用户在表视图的单元格中输入文本时,在单独的表单上显示和更新可能性列表.每次击键后,都需要根据某个单元格的编辑字段中的当前文本来更新列表.

I want to port a program, that responds to every key press while editing a cell in a table view (QTableView with QStandardItemModel). The idea is to show and update a list of possibilities on a separate form while the user is entering a text in a table view's cell. After every key stroke, the list needs to be updated according to the current text in the edit field of some cell.

使用QTableView :: installEventFilter和QEvent :: KeyPress,可以在表视图处于焦点状态时获得每次按键操作,但是单元格文本/模型仅在编辑后更新,这禁止实时更新列表.

Using QTableView::installEventFilter and QEvent::KeyPress, I can get every key press while the table view is in focus, but the cell text / model is only updated after editing, which prohibits live updates of the list.

仅在编辑完成之后而不在用户输入期间发出模型的dataChanged信号.

The model's dataChanged signal is only emitted after editing has finished and not during the user's input.

关于如何解决此问题的任何想法? 我应该使用QItemDelegate吗? 还是应该以某种方式将QLineEdit连接到单元格,并且可以在视觉上看不到它的情况下完成此操作,因此用户似乎仍在直接在单元格内工作?

Any ideas on how to solve this? Should I use a QItemDelegate? Or should a QLineEdit be connected to a cell somehow and can this be done without it visually being apparent, so the user still appears to be working directly inside a cell?

谢谢您的帮助

推荐答案

它有效!调整大小后出现的问题是由于我的bug:-)(位于源代码中的其他位置) 任何改进的建议仍然欢迎!

It works! Problems after resizing were due to a bug of mine :-) (located elsewhere in the source code) Any suggestions for improvement still welcome!

这篇关于具有QStandardItemModel的QTableView:如何在编辑单元格期间执行实时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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