7

I'm building a QuickLook plugin. I want to change the width of the windows that pops up when user hits the spacebar.

I've read there are two keys in the info.plist file of the project where height and width are customisable. Even if I change those values I can't get the size of the preview windows to my desired one.

I don't know what else to try. Any idea?

Thanks!

Andres
  • 11,439
  • 12
  • 48
  • 87

3 Answers3

5

Thought I'd dig a little on this. I have not tried any of the following suggestions, so nobody get their hopes up. I'll assume you're using the generator callback:

OSStatus (*GeneratePreviewForURL)(
    void *thisInterface,
    QLPreviewRequestRef preview,
    CFURLRef url,
    CFStringRef contentTypeUTI,
    CFDictionaryRef options
);

Before anything else, you might manually check the options dictionary argument and verify that the kQLPreviewPropertyWidthKey and kQLPreviewPropertyHeightKey keys are indeed mapped to the desired CFNumber values.

Referring to each of these properties, the Apple QuickLook programming guide says:

Note that this property is a hint; Quick Look might set the width automatically for some types of previews. The value must be encapsulated in a CFNumber object.

(Edit: If your preview representation is flexible, you might try finding a preview type for which QuickLook honors your size hints, as per the statement above. Just a thought.)

Running nm on the QuickLook framework binary revealed some undocumented kQLPreviewProperty-- constants as well as the aforementioned width and height keys. One that caught my attention was kQLPreviewPropertyAutoSizeKey. Recalling Apple's statement about ignoring the hints to set the size automatically, this might be significant? Following the convention in QuickLook.framework/Headers/QLBase.h, you might try declaring

extern const CFStringRef kQLPreviewPropertyAutoSizeKey;

Then you could try associating a CFNumber 0 with that property key in the options dictionary. There are other undocumented keys of note, such as kQLPreviewPropertyAttributesKey.

Back to the Info.plist you mentioned, Apple says about those keys QLPreviewWidth and QLPreviewHeight:

This number gives Quick Look a hint for the width (in points) of previews. It uses these values if the generator takes too long to produce the preview. (emphasis added)

This is where someone makes the terrible suggestion of calling sleep() in your generator. But I'm perplexed as to why Apple would make following the size hints dependent on the generator latency. (?)

Edit: Also note the above statement says the Info.plist hints must be expressed in points (not pixels), a unit dependent on the user's screen resolution.

Community
  • 1
  • 1
  • 1
    The generator creates an image or HTML, so the preview would be based on the natural dimensions of those by default, wouldn't it? – Rob Keniger Dec 03 '13 at 03:26
  • @Keniger, that's interesting. I wonder what effect the CSS min-width property would have in an HTML preview. –  Dec 04 '13 at 15:47
  • Thanks guys for the help. I've already tried to add the min-width. It changes the size of the "html" it self but not the size of the quicklook plugin window. The window is always from the same size... – Andres Dec 05 '13 at 00:43
  • @jrodatus I'm giving you the bounty, I still have this problem but you really spent some time on this so I'm really thanked for your work! I'll keep researching and if I found something I'll update the answer here! Thanks!! – Andres Dec 05 '13 at 01:12
  • Thank you Andres, though I do wish you could've given to someone who actually helped :-/ –  Dec 06 '13 at 18:07
2

Recently I was developing a Quick Look Plugin myself which uses HTML+CSS and faced the same problem. The solution for my was to test the plugin not within Xcode and qlmanage as the executable but instead to try the real .qlgenerator from my user library.

When invoking the generator from my user library, the Quick Look window was resized exactly the way I specified in the *-Info.plist.

0

I've run into the same problem, and may offer some clues: In my case I'm generating an image quick look preview for my custom file format. I initiate the preview context to draw my preview into using

CGContextRef QLPreviewRequestCreateContext(QLPreviewRequestRef preview, CGSize size, Boolean isBitmap, CFDictionaryRef properties);

The curious thing is that if I set isBitmap to true, quick look adjusts the preview panel size to the size specified for the context (up to a certain size at least). But if you set isBitmap to false, it seems to disregard the context size and instead always shows a full size preview panel with the vector graphics image scaled to cover the entire panel.

So, if you use a bitmap graphical preview context, it seems the preview panel will be set to the size of the context you specify. However, I haven't found any way to set the size of the panel when using a vector graphic preview context (which is what I want).

Lostminds
  • 11
  • 3