paolom
7th June 2012, 14:02
Hi,
I'm working with Qt 4.8.2.
I want to display a PDF on Mac Os X.
As the documentation, I need to use QMacCocoaViewContainer.
class PdfMacWidget : public QMacCocoaViewContainer
{
public:
PdfMacWidget( MPMacPDFChildWidget *inParent )
: QMacCocoaViewContainer( 0, inParent ) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MyPdfView *cocoaView = [[MyPdfView alloc] initWithWidget:inParent];
inParent->setCocoaView(cocoaView);
setCocoaView(cocoaView);
[pool release];
}
};
MPMacPDFChildWidget::MPMacPDFChildWidget(QWidget *parent)
: MPPDFChildWidget(parent),
m_cocoaView(NULL)
{
m_pdfWidget = new PdfMacWidget(this);
}
void MPMacPDFChildWidget::loadFile(const QString &fileName)
{
NSString * nsFileName = [NSString stringWithUTF8String:fileName.toUtf8()];
PDFDocument * document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:nsFileName]];
[(PDFView *)m_cocoaView setDocument:document];
[document release];
[(PDFView *)m_cocoaView layoutDocumentView];
[ (PDFView *) m_cocoaView setAutoScales:YES];
}
With Qt 4.8.2 the pdf is not shown cause the size of the m_cocoaView and PdfMacWidget is 0. I've tryed with sizeHint() but it doesn't work.
This code works correctly ( the pdf is shown ) on Qt 4.8.1 and 4.8.0 ( with add setAttribute(Qt::WA_NativeWindow)).
Any suggestion?
I'm working with Qt 4.8.2.
I want to display a PDF on Mac Os X.
As the documentation, I need to use QMacCocoaViewContainer.
class PdfMacWidget : public QMacCocoaViewContainer
{
public:
PdfMacWidget( MPMacPDFChildWidget *inParent )
: QMacCocoaViewContainer( 0, inParent ) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MyPdfView *cocoaView = [[MyPdfView alloc] initWithWidget:inParent];
inParent->setCocoaView(cocoaView);
setCocoaView(cocoaView);
[pool release];
}
};
MPMacPDFChildWidget::MPMacPDFChildWidget(QWidget *parent)
: MPPDFChildWidget(parent),
m_cocoaView(NULL)
{
m_pdfWidget = new PdfMacWidget(this);
}
void MPMacPDFChildWidget::loadFile(const QString &fileName)
{
NSString * nsFileName = [NSString stringWithUTF8String:fileName.toUtf8()];
PDFDocument * document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:nsFileName]];
[(PDFView *)m_cocoaView setDocument:document];
[document release];
[(PDFView *)m_cocoaView layoutDocumentView];
[ (PDFView *) m_cocoaView setAutoScales:YES];
}
With Qt 4.8.2 the pdf is not shown cause the size of the m_cocoaView and PdfMacWidget is 0. I've tryed with sizeHint() but it doesn't work.
This code works correctly ( the pdf is shown ) on Qt 4.8.1 and 4.8.0 ( with add setAttribute(Qt::WA_NativeWindow)).
Any suggestion?