how to choose the correct oil viscosity?

Viscosity of the oil is specified to each car by the manufacture.
Oils with low viscosity are liable to be thin at high temperatures and thus lose their lubrication layer. On the other hand, oils having too high a viscosity may be too thick at low temperatures, which means they will flow slowly to the upper parts of the engine head, not properly penetrate all the moving parts, and even lose their lubrication layer at high RPM.

Therefore, it is very important to choose the correct oil for the engine type and age.

Is the quality of the oil related to its viscosity?

Generally not. The viscosity of the oil is determined by the requirements of the manufacturer that vary with the model and the production year of the specific engine, and it does not necessarily indicate the quality of the oil. ¬†As evidence: tables are given in the vehicle owner’s handbook that specify the different viscosities required in different geographic regions depending on the ambient temperature, even when dealing with the same model.