See the QWidget::customContextMenuRequested() signal or the QWidget::contextMenuEvent() event handler.