First off I don't think you should go for the Nikon D40. My reasoning behind this is that you're only going to get 6 mega pixels from it, and if you're coming from a 10mp camera that could really suck! If you really like the Nikon D40 and want more mega pixels then get the D40x, the x being the magic part because it means it's got the same CCD as it's bigger brothers and gives you 10mp.
I can't say much about the Sony or the Pentax, but I'm going to stir things up a bit now and suggest you take a look at the Canon 400d. I discounted the Canon at first because I'd read reviews that the 18-55mm lens that comes with it is rubbish. In my opinion that's not true (I finally bought one after much debating about 3 months ago and haven't regretted it). In the end for me it came down to the Nikon D40x or the Canon 400d. I was about to get the Nikon but reviews elsewhere had said that the manual settings are fiddly and you have to go into the menus to adjust things like ISO, where as on the Canon functions like ISO, aperture and shutter, etc. all have independant buttons which is brilliant. Also the Canon has a dust prevention system where the low pass filter (a filter that sits just infront of the camera's CCD or CMOS sensor) shakes to get all the dust off during start up and turning off, where as the Nikon does not.
The image quality of the Canon 400d is very good. In fact if you'd like to see some example shots all taken with my 400d you can take a look at my gallery here
http://www.peteblakemore.com/gallery.html (the images have been edited a bit in Photoshop btw!).
At the end of the day it depends on what is right for your situation. I got my DSLR because I wanted to be more creative and access the manual controls and have myself do ALL the work, and because of this the 400d was great. For you it might be different, you might just want a point and shoot camera, or something where you can have full manual but is very easy to use and looks nice. If this is the case then the Nikon D40x is a good camera because it has nicer looking menus and good auto settings but lets you use manual as well. However, the question could be raised that if you just want a simple point and shoot camera and don't really want to get into manual settings much, then why get a DSLR in the first place.
Oh, one more thing that I just remembered about the Canon 400d is that the ISO level goes up to 1600 which is actually fantastic for low light conditions, but don't expect to print huge images with it because it does introduce a bit of noise. It goes does to ISO100 where noise is minimal and the images looks crisp and sharp.
Hope that helps and hasn't confused you anymore by suggesting the Canon!