Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
In the Star Trek: The Next Generation episode "Encounter at Farpoint", Q showed up dressed as a Starfleet officer.
What was his rank?
Assuming this screenshot is correct:
then going by the pips he's definitely Captain.
Going by timestamp 1:22:56 on the Netflix version you can see both Q and Picard standing side-by-side and their ranks are identical. I was going to say captain off the top of my head, but I'm pretty sure that confirms it.
Edit: see Wikis' screen cap for the actual frame.
Required, but never shown