If we were talking about electricity, then the entire gun would have the same charge. Magnets on the other hand have a north and south pole, each of which will affect the compass differently (as you can see [:)])
Any metal that is attracted to a magnet can hold a magnetic charge. If you store your pistol in the same place and relatively the same position, and there is a magnetic field there, it will hold that field for a while.
Heat and striking metal (firing your gun) generally destroys a magnetic field. Heat can be used to strengthen the field only if the metal is heated, then cooled while in a strong magnetic field.
As far as how your gun picked up a magnetic charge, I can give my best guess off the top of my head, but it sounds good to me [:)]. First guess would be that the finish on your CQB might have been applied using an electric charge (electroplating). This would form a temporary electromagnet and possibly some heat. After the process your gun held some of the magnetic charge. Could also be where you store it, any motors or high wattage electrical equipment close by?
edited to add that the barrel has a stronger "pull" because the magnetic field is more concentrated on the smaller pole. If the frame were the same size and material the barrel the strength of the charge would be the same, but opposite polarity.