This is based on my comments and I want to post it as an answer because this aspect has been overlooked by other answers.
Any element of $\mathbb {Q} (\pi) $ is of the form $f(\pi) /g(\pi) $ where $f(x), g(x) \in\mathbb {Q} [x]$. If this equals $\sqrt{2}$ then we have $$2g^2(\pi)=f^2(\pi)$$ and the above is an equality between two real numbers. From here we can't start comparing coefficients as if they are polynomials in some variable.
Rather the above equation shows that $\pi$ is a root of the polynomial $h(x) =2g^2(x)-f^2(x)$. Thus $h(x) $ must be the zero polynomial and then we need to start comparing degree of $f, g$ and equate coefficients. You should be able to derive a contradiction easily by first showing that degree of $f$ must equal that of $g$ and then comparing coefficients.
More generally if $a$ is algebraic and $b$ is transcendental then $a\in\mathbb {Q} (b)$ iff $a\in\mathbb {Q} $. We can assume $a=f(b) /g(b) $ where $f(x), g(x) \in\mathbb {Q} [x] $ and $g$ is non-zero polynomial.
Then $b$ is the root of the polynomial $h(x) =ag(x) - f(x) \in\mathbb {Q} (a) [x] $. The above polynomial is a non-zero polynomial if degree of $f$ is different from that of $g$. And then $b$ becomes algebraic and we reach a contradiction. Hence the degree of $f, g$ must be same and let $p, q$ be their leading coefficients. If $aq-p\neq 0$ then again the polynomial $h$ is non-zero and we get that $b$ is algebraic. Hence we must have $qa=p$ so that $a=p/q$ is rational.
In the above proof we have used the fact that the roots of a polynomial with algebraic coefficients are also algebraic.