your passport acts as your visa to enter Europe
Actually in this case it only acts as a document to allow you into the United Kingdom for an amount of time, as the entry stamp in your passport will say. You will get another stamp when you leave the UK, and then a stamp will be applied at Barcelona allowing entry into the Schengen group of countries (the UK are not Schengen members) and you will collect your luggage and clear customs in Barcelona.
All hand luggage that you leave the airside at Gatwick with will also clear customs at Gatwick, just before you go through the frosted glass doors into the landside of the airport. You will be given a choice of two corridors to go down - red for something to declare, like firearms, drugs, some food, excess cash, alcohol, etc., and green for nothing to declare. If you go through the green door you will be observed but you may not see anybody, and most people walk straight through unless the Customs agents want to have a discussion or believe that you should have gone through the red door; if you go through the red door you will be met and asked what you are declaring.
9 hours isn't actually very long. Or, in your case, almost 9 hours. It may be faster but I would allow 2 hours from touchdown to walking through the frosted glass doors, if your plane is on time, then 30 minutes to 45 to orient yourself (maybe use the toilet or grab a bite, buy a ticket for the train, and wait for the next train, 30 to 40 minutes for the train to reach Victoria Station (more if Thameslink to The City), 15 minutes to work out the route to your first sightseeing stop, walk to the bus or Tube and wait for the tube train or bus to go, and who knows, maybe 15 to 30 minutes to get to that destination. That's nearly 4 hours gone and you haven't done anything yet.
OK, so after you finish your last sightseeing item, 15 minutes back to Victoria, up to a 15 minute wait for a train if you just missed one, 30 minutes on the train, 2:30 (with current security issues) minimum needed before takeoff, and the security theatre begins. So you need to stop sightseeing at least 3 and a half hours before your flight, and I'd make it 4. You don't want to miss that flight to Barcelona at any cost, right?
That gives you about an hour for sightseeing, not much for all that hassle.
But - - - maybe you like cutting it close, maybe your flight from home caught the back end of a hurricane and you arrive in London early, maybe you whizz through Immigration and all the chips fall just right and you can have more time in London.
Are you sure that the incoming flight and the continuation flight are in the same terminal at Gatwick?
just call me an optimist... and somebody who has used Gatwick a lot.