2

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.

DNB5brims
  • 29,344
  • 50
  • 131
  • 195

1 Answers1

5

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.

Josh
  • 2,324
  • 1
  • 21
  • 29
  • Where the hell did you get the JPQuickLookItem? – falkon21 Apr 05 '16 at 14:39
  • 1
    `JPQuickLookItem` is just a simple class that conforms to the [QLPreviewItem](https://developer.apple.com/library/mac/documentation/Quartz/Reference/QLPreviewItem_Protocol/index.html) protocol. I've published the implementation in [this gist](https://gist.github.com/josh-/874826146a0238f5c26aaea404b2b381). – Josh Apr 13 '16 at 11:21