PDA

View Full Version : PDF on Mac OS X with QMacCocoaViewContainer on Qt 4.8.2



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?

sergevk
28th August 2012, 03:59
Hello Paolo (?),
Just found out I have the same issue... Code was working fine with 4.7.x and now that we've upgraded Qt our PDF viewing widget is broken as well.
Did you find a solution to this problem?
Thanks.
-Serge




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?