The optical gain in the active region of quantum cascade laser in an external magnetic field is analyzed. When the magnetic field is applied in the direction perpendicular to the plane of the layers, electron dispersion is broken into series of discrete Landau levels. This additional confinement strongly modifies the lifetime of electrons in the upper state of the laser transition, which is controlled by electron-phonon scattering. Landau levels are magnetically tuneable and, depending on their configuration, phonon emission is either inhibited or resonantly enhanced. This translates into a strong modulation of the population inversion, and consequently of the optical gain by varying the magnetic field. Numerical results are presented for a structure previously considered by Smirnov et al. [Phys. Rev B 66 (2002) 125317] which is designed to emit radiation at λ~11.4µm, with the magnetic field varied in the range 10-60T. The effects of band nonparabolicity are taken into account in this model.