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?
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:
- 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). - Defining a data source and delegate for the
QLPreviewPanel
(if you're worked withNSTableView
s before, this should be pretty familiar). - Configuring the preview panel via the
QLPreviewPanelController
protocol (where you assign the data source and delegate). - 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.
I am just looking at this myself. And have found that Apple provide a good guide with examples in the Docs, Also there is a good example code and files here -> animgifqlgen
I am using the Enriched HTML method, which seems to be working for what I need.
The idea is to Use what ever code you would normally use to parse the info on the file. And use html for the layout and embedding the parsed info,the html is then displayed within the QL Panel. A lot of the normal html code works like size width length,bgcolor,src ...
The example will show how to write the code including the html parts.Which uses a NSMutableString and its appendString and appendFormat: to build the html.
I have not tried the other methods yet.
For testing I just configured the Document Content Type UTIs in the plist and the put a copy of the built product (the plugin) in my /Users/username/Library/QuickLook/ folder.
You may have to create the Folder.
Note that when you want to replace the plugin in the QuickLook folder by drag and dropping a new copy in the folder, it may be in use. Just put the old one in the trash. I also found it helped quitting the Quick Look Helper process using the Activity Monitor app. Doing so made sure I was seeing the results from the New version plugin rather than the old one still in memory. ( I sure someone will tell me I am doing bad ;-) )
来源:https://stackoverflow.com/questions/5303551/how-to-use-qlpreviewpanel