Hazrat Moulana Ashraf Ali Thanwi (rahmatullahi ‘alaih) once mentioned the following:
Expressing gratitude over a favour and being pleased with it, considering it to be purely the grace and mercy of Allah Ta‘ala, is the right which the one enjoying the favour owes to the One who bestowed him with the favour – Allah Ta‘ala. It is in reference to this that Allah Ta‘ala says in the Quraan Majeed:
قُل بِفَضلِ اللّٰهِ وَبِرَحمَتِه فَبِذٰلِکَ فَلیَفْرَحُوا
Say, “In the bounty of Allah and in His mercy – in that let them rejoice.” (Surah Yunus v58)
This form of happiness and joy is actually a form of shukr to Allah Ta‘ala and hence it is praiseworthy and desirable in Deen.
However, contrary to this, there is another form of happiness that equates to pride. This is where a person becomes boastful and happy over the bounty, attributing it to his own effort and achievement, and not to Allah Ta‘ala, and this is ingratitude to the One who bestowed the favour. The root cause of this ingratitude is that a person forgets and loses sight of the fact that this bounty and favour can be taken away from him at any moment. It is in reference to this boastful attitude that Allah Ta‘ala mentions in the Quraan Majeed:
اِذْ قَالَ لَهُ قَوْمُهُ لَا تَفْرَحْ اِنَّ اللّٰهَ لَا یُحِبُّ الفَرِحِینَ
When his people (the people of Qaaroon) said to him, “Do not be filled with boastfulness (in your happiness), indeed Allah does not like those who are filled with boastfulness (in their happiness).” (Surah Qasas v76)
In the case of Qaaroon, he was happy over the wealth itself (not the bounty of Allah Ta‘ala), so look at what an evil end and outcome he met!
When one receives the bounty and blessing, and then reflects that it belongs to Allah Ta‘ala and He may take it away at any time, then the feeling of gratitude that he experiences in his heart at that time is regarded as shukr to Allah Ta‘ala.
(Malfoozaat Hakeemul Ummat 22/176)