[proofplan]
We show that the collection $\mathcal{H} = \{A \in \mathcal{G} : f^{-1}(A) \in \mathcal{E}\}$ of "good sets" is a $\sigma$-algebra, using the fact that preimages commute with all set operations. Since $\mathcal{H}$ contains $\mathcal{Q}$, it contains $\sigma(\mathcal{Q}) = \mathcal{G}$, proving measurability.
[/proofplan]
[step:Define the good collection and show it contains $\mathcal{Q}$]
Let
\begin{align*}
\mathcal{H} = \{ A \in \mathcal{G} : f^{-1}(A) \in \mathcal{E} \}.
\end{align*}
By hypothesis, $\mathcal{Q} \subseteq \mathcal{H}$.
[/step]
[step:Verify $\mathcal{H}$ is a $\sigma$-algebra on $G$]
[claim:H Is A Sigma Algebra]
$\mathcal{H}$ is a $\sigma$-algebra on $G$.
[/claim]
[proof]
First, $f^{-1}(\varnothing) = \varnothing \in \mathcal{E}$ and $f^{-1}(G) = E \in \mathcal{E}$, so $\varnothing, G \in \mathcal{H}$.
Second, if $A \in \mathcal{H}$, then $f^{-1}(A^c) = (f^{-1}(A))^c \in \mathcal{E}$, so $A^c \in \mathcal{H}$.
Third, if $(A_n)_{n=1}^\infty$ is a sequence in $\mathcal{H}$, then
\begin{align*}
f^{-1}\!\left(\bigcup_{n=1}^\infty A_n\right) = \bigcup_{n=1}^\infty f^{-1}(A_n) \in \mathcal{E},
\end{align*}
so $\bigcup_n A_n \in \mathcal{H}$.
[/proof]
[/step]
[step:Conclude measurability and state the special case for real-valued functions]
Since $\mathcal{H}$ is a $\sigma$-algebra containing $\mathcal{Q}$ and $\sigma(\mathcal{Q}) = \mathcal{G}$, we have $\mathcal{G} \subseteq \mathcal{H}$, so $f$ is measurable.
The converse is immediate: if $f$ is measurable, then $f^{-1}(A) \in \mathcal{E}$ for all $A \in \mathcal{G} \supseteq \mathcal{Q}$.
For the special case $G = \mathbb{R}$: since $\mathcal{B}(\mathbb{R}) = \sigma(\{(-\infty, y] : y \in \mathbb{R}\})$, taking $\mathcal{Q} = \{(-\infty, y] : y \in \mathbb{R}\}$ gives that $f$ is measurable if and only if $\{x \in E : f(x) \leq y\} = f^{-1}((-\infty, y]) \in \mathcal{E}$ for all $y \in \mathbb{R}$.
[/step]