Qt - QTableView - Clickable button in table row

后端 未结 2 1702
庸人自扰
庸人自扰 2020-12-30 00:06

I require 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 loo

相关标签:
2条回答
  • 2020-12-30 00:39

    You can use setIndexWidget for that, see the Qt documentation for more information.

    As an example, to embed a push button in the first column of the second row (untested code):

    tableView->setIndexWidget(tableView->model()->index(2, 1), new QPushButton);
    
    0 讨论(0)
  • 2020-12-30 00:54

    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.

    For example,

    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);
      }
    }
    
    0 讨论(0)
提交回复
热议问题