还需打开开关:
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &TableWidget::customContextMenuRequested, this, &TableWidget::showContextMenu);