Qt - QTableView - 表行中的可点击按钮 [英] Qt - QTableView - Clickable button in table row

查看:971
本文介绍了Qt - QTableView - 表行中的可点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 QTableView 的表行中有一个按钮/链接。这是打开一个对话框,允许更有效地编辑该行。

I require the ability to have a button/link within a table row of a QTableView. This is to open a dialog to allow that row to be edited more efficiently.

在网上查找后,我还没有找到一个体面的例子。

After hours of looking on the web I am yet to find a decent example.

我知道这可能是使用 QItemDelegate ,但我不确定如何有一个功能的小部件

I am aware that this is likely to be done using a QItemDelegate, but I am unsure how to have a functional widget within the row without forcing the item into edit mode first.

任何帮助都将非常感激。

Any help would be greatly appreciated.

推荐答案

您可以通过在可点击文本下划线来模拟链接的功能,然后通过cellClicked(row,col)信号捕获单元格点击并检查col == editColumn。

You could emulate the functionality of a link by underlining the clickable text, then capturing the cell click via the cellClicked(row, col) signal and check that col == editColumn. Then row would correspond to which item you are editing.

例如,

数据名称|值1 |值2 |

Data Name | Value 1 | Value 2 | Edit

connect (tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(editSlot(int, int)));

...

void ClassName::editSlot(int row, int col){
  if (col == 3) {
    doWork(row);
  }
}

这篇关于Qt - QTableView - 表行中的可点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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