use QWidget::customContextMenuRequested() and QWidget::actions() to manipulate the state of actions or build your own menu inside that function.