As I've said before
, physics dictates that you cannot have good performance in low-light ("good quality photos in all light conditions
("20X") zoom and
"a compact camera". You will have to prioritize two of those and compromise the third.
That said, if forced to choose between the two cameras you listed, I'd go with the TZ40 because it has better high ISO performance than the HX50V. Not anywhere near what I'd consider "good quality" (i.e. in this case, you will be prioritizing zoom and compactness, while compromising low-light performance), but better than the alternative.