QTableView 并双击单元格 [英] QTableView and double click on a cell

查看:182
本文介绍了QTableView 并双击单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个测试用例编辑器.该编辑器包含 USART 一种发送和接收数据包格式.编辑器是一个表格视图.

I am working on a test case editor. This editor contains USART a transmit and receive packet format. The editor is a table view.

发送和接收数据包的长度为 8 个字节,例如:

The transmit and receive packet is eight bytes long, for example:

0x01 0x02 0x03 ... 0x08

它在我的第五和第六列中.现在,我希望此列中的单元格是只读的,但是当我双击这些列中的任何单元格时,会显示一个弹出窗口小部件.这个小部件将在文本编辑中包含八个框,用户可以在其中输入数据包格式(即八字节长)数据.我可以轻松地将这些数据从弹出窗口、小部件复制回后端的只读单元格.

It is in my fifth and sixth column. Now, I want the cells in this column to be read only, but when I double-click on any cell in these columns a pop-up widget is displayed. This widget will contain eight boxes in the text edit, where the user can enter the packet format (i.e. eight bytes long) data. I can easily copy back this data from pop up, widget to the read only cells in the backend.

这将取消用户的所有策略,例如每个字节之间是否应该有空格.因此,这将消除潜在的人为错误.

This will take away all the policy from the user, like whether or not there should be a space between each byte. Thereby, this will remove potential human errors.

1:是否有双击表格视图单元格的事件处理程序?

1: Is there an event handler for double clicking on the cell of table view?

2:我可以为同一列的每个单元格设置一个通用的双击处理程序吗?

2: Can I have a common double click handler for each cell of the same column?

3:如何使特定列的单元格在表视图中只读,同时保留我可以在最后(即返回)更改它们的值的事实?

3: How can I make the cells of a particular column read only in table view while preserving the fact that I can change their value at the end (i.e. back)?

推荐答案

1:是否有双击表格单元格的事件处理程序查看.

1: Is there an event handler for double clicking on the cell of table view.

注意,您应该使用信号而不是事件:

Note, you should use signals as opposed to events:

void doubleClicked(const QModelIndex & index)

2:我可以为相同的每个单元格设置一个通用的双击处理程序吗?列.

2: Can I have a common double click handler for each cell of the same column.

是的,您可以为每个信号处理上述信号.

Yes, you can handle the signal aforementioned for each.

3:如何使特定列的单元格在表格中只读查看的同时保留我可以更改它们的值的事实结束(即返回).

3: How can I make the cells of a particular column read only in table view while preserving the fact that I can change their value at the end (i.e. back).

这是您需要根据您的意愿(即只读或读写)为模型索引设置的标志:

This is the flag you need to set for the model indices according to your wish (i.e. read only or read write):

Qt::ItemIsEditable 2 可以编辑.

这篇关于QTableView 并双击单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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