Search code examples
swiftmacosquicklook

Set QuickLook window size when previewing with QLPreviewingController.preparePreviewOfFile


I am writing a QuickLook plugin for macOS and everything works, except that I can't set programmatically the window size of the preview.

It starts with 800x600, no matter what I do in the XIB and/or in the code, before and/or after the call to the completionHandler of preparePreviewOfFile.

Other file types, handled by the default plugin, adapts the preview window size to the content of the file. I would like to do just that.

The preview window is resizable by the user and, once resized, keeps the new size when I select another file in the Finder, to go back to 800x600 if I close it and reopen it on a file handled by my plugin.

What am I missing?


Solution

  • QLPreviewingController should set its preferredContentSize so that the window can be sized accordingly.

    https://developer.apple.com/documentation/appkit/nsviewcontroller/1434409-preferredcontentsize