I stumbled on this question while answering the following question:
Given a general wavefunction $\psi(x)$ and an operator $\hat Q$, with eigenvalue spectrum $\{q_r\}$ and corresponding eigenfunctions $\{u_r\left(x\right)\}$, show that the expectation value of $\hat Q$ is given by $$\langle\hat Q\rangle = \int_{-\infty}^\infty{\psi^*\hat Q \psi \,dx}$$
I started of with the ususal definition of the expected value and inserted the identity operator in position representation: $$\langle\hat Q\rangle = \langle \psi|\hat Q|\psi\rangle = \langle \psi|\left(\int dx|x\rangle\langle x|\right) \hat Q\left(\int {dx}'|x'\rangle\langle x'|\right)|\psi\rangle$$
Taking $\langle\psi|$ and $|\psi\rangle$ into the integral gives: $$\left(\int dx\langle \psi|x\rangle\langle x|\right) \hat Q\left(\int {dx}'|x'\rangle\langle x'|\psi\rangle\right)$$
Pulling the 2nd integral into the first:$$\int dx\int {dx}'\langle \psi|x\rangle\langle x'|\psi\rangle\langle x| \hat Q|x'\rangle$$
This is the point where I'm stuck. If $\langle x|\hat Q|x'\rangle = \hat Q \delta(x-x')$, then the last expression would evaluate to the answer. However I don't know why this should be true and even if it is true I wouldn't know how to prove this equality.