Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use QLPreviewPanel?

How do I use QLPreviewPanel? I know it wasn't a public API before, but it is in 10.6. How can I use it to show a preview of a file in a standard QuickLook panel?

like image 398
Seb Jachec Avatar asked Mar 14 '11 19:03

Seb Jachec


2 Answers

Check out the QuickLookDownloader code. It walks you through a couple of things you need to do to incorporate QLPreviewPanel into your code. Some of these include:

  1. Making your objects conform to the QLPreviewItem protocol - this tells Quick Look where to find the file you want to preview (and you are previewing files - you can't pass in custom data).
  2. Defining a data source and delegate for the QLPreviewPanel (if you're worked with NSTableViews before, this should be pretty familiar).
  3. Configuring the preview panel via the QLPreviewPanelController protocol (where you assign the data source and delegate).
  4. Displaying shared preview panel.

Items 1-3 are handled in the MyDocument class of the sample code. Toggling the display is mostly handled in the AppDelegate class. There's also support in the DownloadsTableView class that toggles the QLPreviewPanel via the space key, a la the Finder.

like image 60
Jablair Avatar answered Sep 28 '22 00:09

Jablair


Sadly Apples QuickLookDownloader Demo uses Obj-C. I extended Josh's Demo with a show panel functionality to show how it is done in Swift: Panel and Popover example

like image 28
Deitsch Avatar answered Sep 27 '22 22:09

Deitsch