DNB5brims
DNB5brims

Reputation: 30618

How to put the QLPreviewPanel show as a popover in cocoa?

enter image description here

I would like to make a Popover that can show as a popover like the spotlight search implementation? I can only use traditional way to show a Quicklook window on the centre, but I would like to make something like this:

How can I do so? Thanks.

Upvotes: 2

Views: 1092

Answers (1)

Josh
Josh

Reputation: 2704

This can be achieved by creating a QLPreviewView instance embedded within a NSPopover.

Then, create a NSObject subclass that conforms to the QLPreviewItem protocol and set the previewItem property on your QLPreviewView like when working with the traditional QuickLook QLPreviewPanel.

QLPreviewView *view = [[QLPreviewView alloc] initWithFrame:NSMakeRect(0, 0, 800, 100) style:QLPreviewViewStyleNormal];

JPQuickLookItem *item = [[JPQuickLookItem alloc] init];
item.previewItemURL = [NSURL fileURLWithPath:@"/Users/josh/Desktop/Test.png"];
item.previewItemTitle = @"Test.png";
view.previewItem = item;

I've created a sample Swift implementation here.

Upvotes: 5

Related Questions