We study the synchronization of a superconducting qubit to an external optical field via a mechanical resonator in a hybrid optoelectromechanical system. The quantum trajectory method is employed to investigate synchronization. The bistability in one of the qubit polarization vectors, where the qubit rotates about the polarization vector, is observed for a single quantum trajectory run. The rotation in one of the stable states is synced with the external optical drive. When the number of trajectories is significantly increased, the qubit no longer displays bistability. However, synchronization with less quantum fluctuations is still observed. The scheme could be used to transfer the phase of the microwave qubit's rotation to a long-lived optical photon through synchronization, which may find applications in long-distance quantum communication. Also, this hybrid system can be used to study quantum synchronization.