gaze (off) into space
To stare vacantly or absentmindedly at nothing in particular, usually while one is preoccupied with or distracted by thoughts of something else. I sat at the back of class, gazing off into space, when suddenly the solution came to me. He just gazed into space as his parents lectured him on the importance of paying attention during class.