No. You can gain weight too by over sleeping which happens by the food in your body having a slower rate of digestion and thereby entering the blood and body parts to give you weight.
When you take over-excessive rest, there is also a high possibility of you getting incredibly fat in coming months even when you do not plan to.
Apart from rest, people who have the fatty gene are also at a risk of gaining weight. I have a friend who has the fatty gene. She doesn't eat much but she gains weight in an unusual manner. Unlike me, despite whatever I eat, it is very hard, if not impossible for me to gain weight like her.
So apart from eating fatty foods, over excessive rest, and the fatty genes present in some humans are some of the other causes of weight gain.