Hi all,

I'm trying to write a thin Qt wrapper which allows to scroll a canvas rendered by a 3rd-party class Foo.

This seems to work fine:
Qt Code:
  1. class MyWrapper : public QScrollArea
  2. //class MyWrapper : public QAbstractScrollArea
  3. {
  4. Q_OBJECT
  5.  
  6. private:
  7. Foo _foo;
  8. QLabel _canvas;
  9.  
  10. public:
  11. MyWrapper()
  12. {
  13. setWidget(&_canvas); //QScrollArea
  14. // setViewport(&_canvas); //QAbstractScrollArea
  15. _canvas.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
  16. _foo.setHook(hook, this);
  17. }
  18.  
  19. //3rd-party class Foo signals "render finished" through this callback
  20. friend void hook(void *data, bool canceled);
  21.  
  22. public slots:
  23. void showRendered()
  24. {
  25. QImage img(reinterpret_cast<const uchar *>(_foo.buffer()),
  26. _pdfView->bufferWidth(),
  27. _pdfView->bufferHeight(),
  28. QImage::Format_ARGB32);
  29. _canvas.setPixmap(QPixmap::fromImage(img));
  30. _canvas.adjustSize();
  31. }
  32.  
  33. protected:
  34. void paintEvent(QPaintEvent *event)
  35. {
  36. _foo.update();
  37. }
  38.  
  39. void resizeEvent(QResizeEvent *event)
  40. {
  41. _foo.resize(viewport()->width(), viewport()->height());
  42. }
  43. };
  44.  
  45. void hook(void *data, bool canceled)
  46. {
  47. MyWrapper*wrapper = (PdfWidget *)data;
  48. //Foo::update() spawns a sparate thread
  49. QMetaObject::invokeMethod(wrapper, "showRendered", Qt::AutoConnection);
  50. }
To copy to clipboard, switch view to plain text mode 

As Foo provides everything needed to move/zoom/resize/pan the canvas, QAbstractScrollArea seems more appropriate to inherit from.
However, if I apply the changes indicated in the above code snippet, nothing is painted at all in the viewport.

What am I missing? Any help appreciated.