Qt5 compatibility

This commit squashes all the changes in the Qt5 branch relative to master.

Backward compatibility with Qt4 is retained.

Original authors:

- Philip Kaufmann
- Jonas Schnelli