ViaMichelin estimates the driving time via the shortest route at about 16 hours (with no stops), and folks here tend to think VM's estimates are optimistic. The cost in gas and tolls is estimated at 235 euros. You'd need to add car-rental expenses to that, and of course the extra charge for picking up a vehicle in Spain and dropping it in Czechia would probably be very high (many hundreds of euros, I would guess). You might want two or more people to share the driving, which I suspect could add to the basic rental cost as well. So I think driving would be very costly. But there are lots of interesting places along the way:
Spain: Girona, Figueres
France: Montpellier, Nimes, Arles, Avignon, Lyon, Colmar, Strasbourg
Germany: Heidelberg, Rothenburg od Tauber, Nurnberg
Or you could spend an extra 3 hours or so driving and instead be near:
Spain: same as above
France: Montpelier, Arles, Aix-en-Provence, Marseille, Nice
Italy: Genoa, Lake Garda, Verona, the Dolomites
Austria: Innsbruck
Germany: Munich, Regensburg
Sad to say, the rail options all seem to take a bit over 24 hours. You can take a look at what's available on the Deutsche Bahn website just to get an idea of routing options, but really, just looking at a map might be better. As with driving, there are lots of interesting places more or less along the way. It all depends on what interests you.
If you want to spend your time in Barcelona and/or Prague rather than at points in between, flying is certainly an option. Several airlines offer non-stop flights. You can check the possibilities on Skyscanner.com.