I had this problem not only with elementaryOS, but with Lubuntu as well. Its a driver problem.
Do not use the nvidia
drivers included in the AppCenter, this is a known bug that happens with the legacy drivers included in most LTS variations of Ubuntu.
To fix just update your drivers using nvidia's driver repo.
sudo apt-get purge nvidia*
sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update
Check your Graphics cards for a compatible Driver, for example, my GPU is Nvidia GeForce GTX 1050, so it's compatible with the Latest Short Lived branch which is nvidia-396
as the date this answer was originally written.
sudo apt-get install nvidia-XXX
For Elementary OS 5.0 (and other distros based on 18.04 LTS) the package name changed:
sudo apt-get install nvidia-driver-XXX
Replace XXX with the version your GPU is compatible with. The latest, the better.
Restart, the problem should be fixed.
Sources: