objective-ccocoaquicklook

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?


Solution

  • 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.