How can I find the ratio of molecular masses using the ideal gas equation?
The ideal gas equation is $PV = nRT$
But for this problem V, R, and T are constants. So we can collect terms as:
$\dfrac{P}{n} = \dfrac{RT}{V}$
So $\dfrac{P_A}{n_A} = \dfrac{P_B}{n_B}$
Now you correctly determined the number of moles of A and B.
$n_A = \dfrac{4}{\text{MW}_A}$
$n_B = \dfrac{8}{\text{MW}_B}$
But you need to consider the partial pressures of A and B.

The cylinder was empty before A was added, and after A was added the pressure was 1 atmosphere. So the partial pressure of A is 1 atmosphere.
Before B is added the pressure is 1 atmosphere and after B is added the pressure is 1.5 atmospheres.  So the partial pressure of B is 0.5 atmospheres.

$P_A = 1$
$P_B = 0.5$
Now substituting into our simplified equation
$\dfrac{1}{\frac{4}{\text{MW}_A}} = \dfrac{0.5}{\frac{8}{\text{MW}_B}}$
$\dfrac{8}{\text{MW}_B} = \dfrac{2}{\text{MW}_A}$
$\dfrac{\text{MW}_A}{\text{MW}_B} = \dfrac{2}{8} = \dfrac{1}{4}$