//class MyWrapper : public QAbstractScrollArea
{
Q_OBJECT
private:
Foo _foo;
public:
MyWrapper()
{
setWidget(&_canvas); //QScrollArea
// setViewport(&_canvas); //QAbstractScrollArea
_foo.setHook(hook, this);
}
//3rd-party class Foo signals "render finished" through this callback
friend void hook(void *data, bool canceled);
public slots:
void showRendered()
{
QImage img
(reinterpret_cast<const uchar
*>
(_foo.
buffer()),
_pdfView->bufferWidth(),
_pdfView->bufferHeight(),
_canvas.
setPixmap(QPixmap::fromImage(img
));
_canvas.adjustSize();
}
protected:
{
_foo.update();
}
{
_foo.resize(viewport()->width(), viewport()->height());
}
};
void hook(void *data, bool canceled)
{
MyWrapper*wrapper = (PdfWidget *)data;
//Foo::update() spawns a sparate thread
QMetaObject::invokeMethod(wrapper,
"showRendered", Qt
::AutoConnection);
}
class MyWrapper : public QScrollArea
//class MyWrapper : public QAbstractScrollArea
{
Q_OBJECT
private:
Foo _foo;
QLabel _canvas;
public:
MyWrapper()
{
setWidget(&_canvas); //QScrollArea
// setViewport(&_canvas); //QAbstractScrollArea
_canvas.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
_foo.setHook(hook, this);
}
//3rd-party class Foo signals "render finished" through this callback
friend void hook(void *data, bool canceled);
public slots:
void showRendered()
{
QImage img(reinterpret_cast<const uchar *>(_foo.buffer()),
_pdfView->bufferWidth(),
_pdfView->bufferHeight(),
QImage::Format_ARGB32);
_canvas.setPixmap(QPixmap::fromImage(img));
_canvas.adjustSize();
}
protected:
void paintEvent(QPaintEvent *event)
{
_foo.update();
}
void resizeEvent(QResizeEvent *event)
{
_foo.resize(viewport()->width(), viewport()->height());
}
};
void hook(void *data, bool canceled)
{
MyWrapper*wrapper = (PdfWidget *)data;
//Foo::update() spawns a sparate thread
QMetaObject::invokeMethod(wrapper, "showRendered", Qt::AutoConnection);
}
To copy to clipboard, switch view to plain text mode
Bookmarks