A barayta (Berachot 31a) says (translations edited from link):
תנו רבנן אין עומדין להתפלל לא מתוך עצבות ולא מתוך עצלות ולא מתוך שחוק ולא מתוך שיחה ולא מתוך קלות ראש ולא מתוך דברים בטלים אלא מתוך שמחה של מצוה
The Sages taught: One may neither stand to pray from sorrow nor from laziness, nor from laughter, nor from conversation, nor from frivolity, nor from purposeless matters. Rather, from the joy of a mitzva.
Thus, praying while sad isn't considered proper.
The Rambam (Laws of Prayer 4:15) brings this as law, according to which one is forbidden to pray while unable to concentrate.
כַּוָּנַת הַלֵּב כֵּיצַד. כָּל תְּפִלָּה שֶׁאֵינָהּ בְּכַוָּנָה אֵינָהּ תְּפִלָּה. וְאִם הִתְפַּלֵּל בְּלֹא כַּוָּנָה חוֹזֵר וּמִתְפַּלֵּל בְּכַוָּנָה. מָצָא דַּעְתּוֹ מְשֻׁבֶּשֶׁת וְלִבּוֹ טָרוּד אָסוּר לוֹ לְהִתְפַּלֵּל עַד שֶׁתִּתְיַשֵּׁב דַּעְתּוֹ. לְפִיכָךְ הַבָּא מִן הַדֶּרֶךְ וְהוּא עָיֵף אוֹ מֵצֵר אָסוּר לוֹ לְהִתְפַּלֵּל עַד שֶׁתִּתְיַשֵּׁב דַּעְתּוֹ. אָמְרוּ חֲכָמִים יִשְׁהֶה שְׁלֹשָׁה יָמִים עַד שֶׁיָּנוּחַ וְתִתְקָרֵר דַּעְתּוֹ וְאַחַר כָּךְ יִתְפַּלֵּל:
Concentration of the mind—how is this condition [to be fulfilled?] Any prayer uttered without mental concentration is not prayer. If a service has been recited without such concentration, it must be recited again devoutly. If a person finds that his thoughts are confused and his mind is distracted, he may not pray till he has recovered his mental composure. Hence, on returning from a journey or if one is weary or distressed*, it is forbidden to pray till his mind is composed. The sages said that he should wait three days till he is rested and his mind is calm, and then he recites the prayers.
*or more accurately: "while one is weary or distressed"
According to this law, a person shouldn't pray if he is so distressed that it prevents him from concentrating. If he did pray, it isn't a real prayer; once he is able to concentrate again, he still has to make it up.
These days, people tend not to put this law into practice. The reason why is because the Maharam of Rotenburg claims that nowadays we don't pray with concentration anyway, so lack of concentration is no longer a reason to skip prayer (Tur Orach Chayim 98, Shulchan Aruch 98:2). For the same reason, the Tur says that we no longer repeat the prayer if we didn't concentrate, because we assume we will fail once again to concentrate (Tur 101, Rama 101:1). Perhaps the only way this law has survived into current practice is in saying Ashrei and other psalms before the prayer, which is supposed to put you into the requisite mood of the joy of fulfilling the commandments (Tur 93, Shulchan Aruch 93:2).
If sayings the psalms or otherwise meditating before prayer isn't enough to take away your sadness before praying, and you want guidance for your specific situation, you may want to seek advice from a rabbi for what to do regarding prayer.