QTableView and double click on a cell

梦想的初衷 提交于 2020-12-06 03:34:27

问题


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

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: Is there an event handler for double clicking on the cell of table view?

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

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)?

enter image description here


回答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: 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: 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 It can be edited.



来源:https://stackoverflow.com/questions/19057940/qtableview-and-double-click-on-a-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!