开发者

Resizing a QTCaptureView embedded in a Qt app

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 muc开发者_JS百科h appreciate it.


How to set NSView size programmatically?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜