Set QuickLook window size when previewing with QLPreviewingController.preparePreviewOfFile

Viewed 336

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?

2 Answers

The accepted answer, setting preferredContentSize, seems to break the autoresizing of all subviews in macOS Catalina. After setting it, the content will no longer track the preview window size when the user resizes it manually or enters fullscreen.

See my question here.

So I'd like to add the following to the answer: There is no known way to do this on macOS Catalina without breaking autoresizing, but it works fine on macOS Big Sur. The preferredContentSize line should be wrapped in a #available(macOS 11, *) guard.

Related