At the very least, you'll need 5 hours if you plan to visit the palace itself, the Petit and Grand Trianon, the Queen's Hamlet and the gardens. It would be wiser to set aside a full day if at all possible or you may find yourself rushing.