Context. The diffuse ionized gas (DIG) constitutes the largest fraction of the total ionized interstellar matter in star-forming galaxies, but it is still unclear whether the ionization is driven predominantly by the ionizing radiation of hot massive stars, as in H II regions, or whether additional sources of ionization have to be considered. Key to understanding the ionization mechanisms in the DIG is the line emission by the ionized gas. Aims. We systematically explore a plausible subset of the parameter space involving effective temperatures and metallicities of the ionizing sources, the effects of the hardening of their radiation by surrounding “leaky” H II regions with different escape fractions, as well as different scenarios for the clumpiness of the DIG, and compute the resulting line strength ratios for a number of diagnostic optical emission lines. Methods. For the ionizing fluxes we computed a grid of stellar spectral energy distributions (SEDs) from detailed, fully non-LTE model atmospheres that include the effects of stellar winds and line blocking and blanketing. To calculate the ionization and temperature structure in the interstellar gas we used spherically symmetric photoionization models and state-of-the-art three-dimensional (3D) non-LTE radiative transfer simulations, considering hydrogen, helium, and the most abundant metals. We first applied these methods to classical H II regions around hot stars, using the model SEDs at different metallicities and effective temperatures as ionizing fluxes, and compute the SEDs of the escaping radiation for different escape fractions of hydrogen-ionizing photons. In a second step, we studied the effects of the escaping radiation on the more dilute and extended DIG. Using 3D models simulating a section of a galactic spiral arm, we computed the ionization structure in the DIG for different scenarios for the inhomogeneity of the gas, assuming ionization by a stellar population SED based on plausible parameters. Results. We provide quantitative predictions of how the line ratios from H II regions and the DIG vary as a function of metallicity Z, stellar effective temperature Teff, and escape fraction fesc from the H II region. The range of predicted line ratios reinforces the hypothesis that the DIG is ionized by (filtered) radiation from hot stars. At one-tenth solar metallicity, radiation hardening is mostly due to hydrogen and helium, whereas at solar metallicity absorption by metals plays a significant role. The effects of hardening are seen primarily in the increase in the emission line ratios of the most important cooling lines of the gas, [N II]∕Hβ and [O II]∕Hβ at lower Teff, and [O III]∕Hβ at higher Teff. For low Teff nearly the entire He I-ionizing radiation is absorbed in the H II regions, thereby preventing the formation of high ionization stages such as O III in the DIG. The ionization structure of the DIG depends strongly on both the clumping factor fcl = 〈nH2〉/〈nH2〉 and the large-scale distribution of the gas. In our simulations about 10% of the ionizing radiation produced by hot massive stars in a spiral arm is sufficient to ionize the DIG up to a height of approximately 1 kpc above the galactic plane for a clumping factor close to the observed value of fcl ~ 5. Even small changes in simulation parameters such as the clumping factor can lead to considerable variation in the ionized volume. Both for a more homogeneous gas and a very inhomogeneous gas containing both dense clumps and channels with low gas density, the ionized region in the dilute gas above the galactic plane can cease to be radiation-bounded, allowing the ionizing radiation to leak into the intergalactic medium. Comparison of observed and predicted line ratios indicates that the DIG is typically ionized with a softer SED than predicted by the chosen stellar population synthesis model.