The current style Carlon old work boxes with the auto-swing out ears work
superbly to mount directly on the drywall. But you want to mount to a stud, so
Here is a link to a Carlon model that nails to the front of the stud.
They also make it in one piece plastic and you would just need a fairly
small cutout to get the bracket onto the stud, perhaps a large switch cover
would hide it if you don't want to do the small drywall repair.
But with this adjustable model, I *think* you can remove the bracket, slide it
through the hole and onto the stud (flatten the nailing ears on the bracket),
nail it through the drywall, then slide the box into the grooves.