Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting an NSImage from an NSProgressIndicator
    primarykey
    data
    text
    <p>I need to put the image from an NSProgressIndicator into an NSOutlineView Cell. I have written up code that does this for a determinate indicator and it works just great:</p> <pre><code>NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)]; [progressIndicator setStyle:NSProgressIndicatorSpinningStyle]; [progressIndicator setIndeterminate:NO]; [progressIndicator setMaxValue:100.0]; [progressIndicator setDoubleValue:somePercentage]; NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]]; [progressIndicator release]; return [updateImage autorelease]; </code></pre> <p>I have tried to modify the code to also give me indeterminate indicator images. However for the indeterminate case, I always get a blank 16x16 image. (I have confirmed this by writing the image to a file in each case, the determinate case gives me the progress indicator image, the indeterminate case is always 16x16 white square).</p> <p>The modified code is:</p> <pre><code>if(self.lengthUnknown) { NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)]; [progressIndicator setStyle:NSProgressIndicatorSpinningStyle]; [progressIndicator setIndeterminate:YES]; NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]]; [progressIndicator release]; return [updateImage autorelease]; } else { // Same code as the first listing, this case works fine } </code></pre> <p>Do indeterminate progress indicators use some type of drawing that causes -dataWithPDFInsideRect: to be unable to capture their image?</p> <hr> <p>More information: I tried setting the progress indicator to not use threaded animation as well as trying to grab the contents through NSImage's lockFocus method as suggested below but neither of those attempts made a difference.</p> <p>The progress indicator cell code that Dave mentions below (<a href="http://www.harmless.de/cocoa-code.php" rel="nofollow noreferrer">AMIndeterminateProgressIndicatorCell</a>) is a great workaround, but I would still like to know why I can't use the same technique that works with the determinate mode.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload