A cowboy hat was a type of hat with a high crown and wide brim that was worn by Humans, notably in the Ancient West. (ENT: "The Catwalk", "North Star"; TOS: "Spectre of the Gun"; TNG: "A Fistful of Datas"; DS9: "It's Only a Paper Moon") This type of hat was also found on Miri during the 23rd century, and was worn by an Only boy. (TOS: "Miri")
A Stetson was a particular design of cowboy hat. In the alien reality based on the novel, Hotel Royale, the gambler Texas wore a tan-colored Stetson. He let Data wear it for good luck. (TNG: "The Royale") Likewise, a Boss of the Plains, was another type of cowboy hat, with a high crown and a wide, stiff brim. Morgan and Virgil Earp both wore this type of hat. (TOS: "Spectre of the Gun")
The Stetson hat worn by Texas was identified in the episode's script.
According to a commercial, the Spicy Ranch Tribbles cereal box had a drawing of a cartoon tribble dressed as a sheriff from the Ancient West that was wearing cowboy boots, a bandanna and a cowboy hat. (ST: "The Trouble with Edward")