Well, I just saw Dan Vellerman's proof (hint actually), which is very elegant, and which I did not think of.
I will nevertheless add the proof that $f(x)=x$ on $\mathbb{Q}$ because the induction techniques used might be useful for some.
Let's prove that $f(x)=x$ on $\mathbb{Q}$.
Notice that $f(0) = -f(-0) = -f(0)$. Therefore $f(0)=0$.
Let's prove $f(x+n)=f(x)+n$ for all $n\in\mathbb{N}$. For $n=0$ this is obiously true. By induction $f(x+n+1) = f(x+1+n) = f(x+1)+n = f(x)+1+n = f(x) + n+1$. Therefore it is true for all $n\in\mathbb{N}$.
Let us now prove $f\left( \frac{a}{b} \right) = \frac{a}{b}$ for all $a\in \mathbb{Z}$ and $b\in\mathbb{N}^+$. Suppose that $a\in\mathbb{N}$ and continue by induction on $a$. If $|a|=0$ we reduce to the first case above. Otherwise:
$$
f\left( \frac{a}{b} \right) = \frac{f\left( \frac{b}{a}\right) }{\left(\frac{b}{a}\right)^2} = \frac{f\left( \frac{(b \mod a) + \lfloor \tfrac{b}{a} \rfloor a}{a} \right) }{\left(\frac{b}{a}\right)^2} = \frac{f\left( \frac{(b \mod a) }{a} + \left\lfloor \tfrac{b}{a} \right\rfloor \right) }{\left(\frac{b}{a}\right)^2} = \frac{f\left( \frac{(b \mod a) }{a}\right) + \left\lfloor \tfrac{b}{a} \right\rfloor }{\left(\frac{b}{a}\right)^2} = \frac{\frac{(b \mod a) }{a} + \left\lfloor \tfrac{b}{a} \right\rfloor }{\left(\frac{b}{a}\right)^2} = \frac{\frac{b}{a}}{\left(\frac{b}{a}\right)^2} = \frac{a}{b}
$$
Note that the induction step was used in saying that $f\left(\frac{b \mod a}{a}\right) = \frac{b \mod a}{a}$ since $(b \mod a) < a$.
Finally if $a<0$ then $f\left(\frac{a}{b}\right) = f\left(-\frac{|a|}{b}\right) = -f\left(\frac{|a|}{b}\right) = -\frac{|a|}{b}= \frac{a}{b}$.