0

So, I want to have an app in Mac that will show a live video preview through my iSight while allowing users to take snapshots. Basically, it's similar to the Still Motion Demo, except now I have to make it work under a Qt app. That is, I'm having mm files that are mostly adhering to the c++ structure, with occasional Obj-c messaging. Currently, I'm having problems with placing the QTCaptureView with the rest of the Qt module.

Right now, I have managed to place it into my Qt gui through QMacCocoaViewContainer, and wanted to resize it to an appropriate size; since we can't use the Interface Builder anymore, I have to code it somehow. I've tried setting it's frame and bounds right after I created it, but it's not making any difference.

CCaptureViewWidget::CCaptureViewWidget(QWidget *parent) :
    QMacCocoaViewContainer(0, parent)
{
    NSAutoreleasePool *pool   = [[NSAutoreleasePool alloc] init];

    NSRect kVideoFrame = NSMakeRect( 100.0f, 100.0f, 400.0f, 300.0f );
    QTCaptureView *camView = [[QTCaptureView alloc] initWithFrame:kVideoFrame];    
    [camView setFrame:kVideoFrame];
    [camView setBounds:kVideoFrame];

    NSRect ourPreviewBounds = [ camView previewBounds ];

    NSColor *pFillColor = [ [NSColor colorWithDeviceRed:0.0f green:1.0f blue:0.0f alpha:1.0f] copy];
    [camView setFillColor:pFillColor];

    [camView setPreservesAspectRatio:YES];
    [camView setNeedsDisplay:YES];

    setCocoaView( camView );

    [camView release];
    [pool   release];

}

The ourPreviewBounds, as far as I can tell from the debuger in Xcode, has a size of 0x0, even after the setFrame and setBounds call. And just to prove that camView is valid, I did manage to change the fill color of the QTCaptureView.

I read from sources that overriding QTCaptureView's previewBounds might be an option, but I haven't been able to find any working examples of that.

If anyone can give me a hint as to how to resize a QTCaptureView outside of the Interface Builder and inside the code, I will very much appreciate it.

Ingrid Wu
  • 81
  • 1
  • 1
  • 4

1 Answers1

0

How to set NSView size programmatically?

Community
  • 1
  • 1
yolo
  • 2,757
  • 6
  • 36
  • 65
  • Thanks, that's helpful. Unfortunately, it didn't solve the problem. In fact, it turns out to be a QMacCocoaViewContainer issue; apparently, the wrapped-in QTCaptureView is scaled according to the CCaptureViewWidget/QMacCocoaViewContainer parent, so I'm supposed to resize CCaptureViewWidget using setGeometry instead. – Ingrid Wu May 02 '11 at 06:50