code: def contextMenuEvent(self, event):
          
          state = self.has_selected_text()
          self.copy_action.setEnabled(state)
          self.cut_action.setEnabled(state)
          self.delete_action.setEnabled(state)
          self.menu.popup(event.globalPos())
          event.accept()
docs: Reimplement Qt method