It turns out recording your Qt screen/widget from your Qt code as a video is quite tricky.
I created the QtScreenGrabber for making this process faster and easier. It makes it this easy to record your widget and output to a video file:
ScreenGrabber *grabber = new ScreenGrabber; grabber->setup(QString("output.mpg"), width, height); grabber->setPixmapSourceWidget(view); grabber->startRecording(20); // record for 20 seconds
You can find the full example here on GitHub:
This is for capturing your widget as a video, but if you need to save the screen once in a while there is an example for that distributed with Qt examples.