I noticed that certain soldier's uniforms, such as WW1 German chaplains, have hats that look akin to American cowboy hats. On a tour of Colorado decades ago, the guide told us that American cowboy hats were shaped for the purposes of horse riding. Not only sun protection, but branch protection if you get too close to shurbbery or trees while riding on a fast horse.
I wouldn't say that they were "cowboy hats" but the other way round, the hats worn by cowboys are derived from the Mexican wide brimmed sombreros, and these probably by Spanish wide brimmed "cordobes" hats (as worn by Zorro, for instance). Certainly, when a wide brimmed hat is made of soft felt, its brim tends to be floppy and cumbersome, and its easier to handle a rifle (or a musket) when one side of the hat brim is turned upwards (comme un mousquetaire, n'est ce pas?). Hunters adopted the wide brim for sun protection and after them, soldiers too.