Can I use pex for this connection between the shower and the tub faucet?
Yes, you can. But there's an important caveat here. The other connectors are using Sharkbites, which are push connectors. The two in your picture are a compression fitting. You'll either want a crimp ring or a clamp ring to secure the pex to the fitting. These might require a special tool. You might also get away with using a regular screw clamp.