It is one of those phrases that many people are sure they know the origin of.
Francis Grose, in his 1785 edition of The Dictionary of the Vulgar Tongue, defines it like this: "To mind one's P's and Q's; to be attentive to the main chance."
Thomas Dekker later used the term inWest-ward Hoe, a joint work with John Webster, 1607:
"At her p. and q. neither Marchantes Daughter, Aldermans Wife, young countrey Gentlewoman, nor Courtiers Mistris, can match her". In that piece, it is less apparent that 'p. and q.' refer to a form of clothing.
'Mind your Ps and Qs' probably derives from one of these:
1. Mind your pints and quarts. This is suggested as deriving from the practice of chalking up a tally of drinks in English pubs
2. Advice to printers' apprentices to avoid confusing the backward-facing metal type lowercase Ps and Qs,
3. Mind your pea (jacket) and queue (wig). Pea jackets were short rough woollen overcoats. Perruques were full wigs worn by fashionable gentlemen.
4. Mind your pieds (feet) and queues (wigs). This is suggested to have been an instruction given by French dancing masters to their charges.
5. Another version of the 'advice to children' origin has it that 'Ps and Qs' derives from 'mind your pleases and thank-yous''.
So, take your choice.