Surface segregation of In atoms during molecular-beam epitaxy and its influence on the energy levels in strained piezoelectric InGaAsGaAs and InGaNGaN quantum wells (QWs) are investigated theoretically. It is shown that these effects modify the electronic states in the QW and the emission energy in the photoluminescence (PL) spectra. In this work, we solve analytically the Schrödinger equation in the absence of electric field, taking into account the shape changes in the QWs due to the segregation of In atoms during the growth process of the semiconductor heterostructures. Furthermore, the influence of the built-in electric field due to the piezoelectric effect on the PL emission is calculated by considering a variational electron wave function to calculate the ground-energy transitions inside the active region in the heterostructure. In particular, we apply this model to the case of indium segregation in InGaAsGaAs for moderate internal electric fields. The transition energy calculations between the confined electron and hole states as a function of the well width for different temperatures and In composition are in agreement with the measured PL energy peaks.