Use the same logic as MPL uses when picking Qt interface.

Thanks to Michael Droettboom (https://github.com/matplotlib/matplotlib/pull/2221#issuecomment-21108901)