I have class defined as : #ifndef KCANVAS_H
#define KCANVAS_H

#include <Qt3Support/q3scrollview.h>
#include <QtGui/qpen.h>
#include "KItem.h"

class KEvent;
class QPoint;
class QPixmap;

class KCanvas : public Q3ScrollView
              , public KItem
{
   Q_OBJECT
   Q_INTERFACES(KItem)

public:
  // Repaint callback
  typedef void (*RepaintProc_t)(KCanvas*);

  // Event callback
  typedef void (*EventProc_t)(KCanvas*, KEvent* );

  explicit KCanvas( QWidget* parent = nullptr, const char* name = nullptr );

  ~KCanvas( ) override;

  // Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).
  void drawLine( int x1, int y1, int x2, int y2 );

  // Draws the text starting at point (x, y) and using the default KPlus font.
  void drawText( int x, int y, const char* text );

  // Draws the text starting at point (x, y) and using the font "font".
  void drawText( int x, int y, const char* text, const QFont& font );

  void drawText( int x, int y, int width, int height, const char* text);

  void drawText( int x, int y, int width, int height, const char* text,
          int flags);

  void drawText( int x, int y, int width, int height, const char* text,
          const QFont& font );

  void drawText( int x, int y, int width, int height, const char* text,
          int flags, const QFont& font );

  // Draws the rectangle defined by the point (x, y)
  // and the dimensions w and h.
  void drawRect( int x, int y, int w, int h, const QPen& = QPen() );
  void drawRect( int x, int y, int w, int h, int color ) ;

  // Draws the selection rectangle directly onto the viewport
  // This must only be called from the Repaint_Notify!
  void drawSelectionRect( int x, int y, int w, int h, int color );

  // Draws the pixmap image into the rectangle defined by the point (x, y)
  // and the dimensions w and h.
  // If needed, the pixmap is scaled to fit the rectangle.
  void drawPixmap( int x, int y, int w, int h, const QPixmap& image );

  // Displaying the elements...
  void setRepaintProc(RepaintProc_t repaint);

   void setEventProc(EventProc_t event);

  void removeContents();

  void reparent ( QWidget * parent, const QPoint & p, bool showIt = FALSE );
  void reparent ( QWidget * parent, Qt::WFlags f, const QPoint & p, bool showIt = FALSE ); // to avoid 'hide'warning.

  void resizeContents(int width, int height) override;
  void clear();

  // methods transferred from canvas_xv.c
  void setWidth(int width);
  void setColors(int fg, int bg);
  QFont findFont() const;
  QFont findBoldFont() const;
  QFont selectFont(int bold, int size) const;

protected:
  bool eventFilter( QObject*, QEvent* ) override;
  void drawContents( QPainter*, int, int, int, int) override;

private:
  // Not implemented - Just to avoid compiler warning
  void drawContents( QPainter* ) override;

  //Shrinkable
  void setParent(QWidget* parent);

  // Paint callback
  RepaintProc_t repaintCB_;

  class Private;
  Private* const d;  
};

#endif // KCANVAS_H

#endif // KCANVAS_H and implemented as : #include "KCanvas.h"
#include <QtCore/qdebug.h>
#include "KEvent.h"
#include "KFrame.h"

#include <QtGui/qpainter.h>
#include <QtCore/qrect.h>
#include <QtGui/qfont.h>
#include <QtCore/qobject.h>
#include <QtGui/qapplication.h>
#include <QtCore/qpoint.h>
#include <QtGui/qpixmap.h>
#include <QtGui/qevent.h>
#include <Qt3Support/q3scrollview.h>

class KCanvas::Private
{
public:
    Private()
	: eventCB_( nullptr )
    {}

    // Event callback
    EventProc_t eventCB_;

    // The pixmap we draw into (so that we can do outside of paintEvents)
    QPixmap pixmap_;
};

void KCanvas::setParent(QWidget* parent)
{
    if(KFrame* frame = dynamic_cast<KFrame *> (parent))
    {
       Q3ScrollView* scrollView = frame->qScrollView();
        if(!frame->isResizable() || (scrollView !=nullptr) )
        {
            if(!scrollView)
                frame->makeShrinkable();
	    this->reparent(parent, this->pos(), false);
        }
    }
}

KCanvas::KCanvas( QWidget* parent, const char* name )
  : Q3ScrollView( parent, name )
  , repaintCB_( nullptr )
  , d(new Private)
{
  setInstance( parent );

  setSizePolicy( QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred) );
  setParent(parent);
}

KCanvas::~KCanvas( )
{
  delete d;
}

void KCanvas::drawLine( int x1, int y1, int x2, int y2 )
{
  QPainter painter(&d->pixmap_);
  painter.drawLine(x1, y1, x2, y2);
}

void KCanvas::drawText( int x, int y, const char* text )
{
  const QFont kplusFont = QApplication::font();

  this->drawText(x, y, text, kplusFont);
}

void KCanvas::drawText( int x, int y, const char* text, const QFont& font )
{
  QString qText(text);
  QPainter painter(&d->pixmap_);

  painter.setFont(font);
  painter.drawText(x, y, qText);
}

void KCanvas::drawText( int x, int y, int width, int height, const char* text)
{
  const QFont kplusFont = QApplication::font();

  this->drawText(x, y, width, height, text, kplusFont);
}

void KCanvas::drawText( int x, int y, int width, int height, const char* text,
        int flags)
{
  const QFont kplusFont = QApplication::font();

  this->drawText(x, y, width, height, text, flags, kplusFont);
}

void KCanvas::drawText( int x, int y, int width, int height,
        const char* text, const QFont& font )
{
    int flags = Qt::TextShowMnemonic | Qt::AlignVCenter | Qt::AlignLeft;
    this->drawText(x, y, width, height, text, flags, font);
}

void KCanvas::drawText( int x, int y, int width, int height,
        const char* text, int flags, const QFont& font )
{
  QString qText(text);
  QPainter painter(&d->pixmap_);

  painter.setFont(font);
  painter.drawText(x, y, width, height, flags, qText);
}

void KCanvas::drawRect( int x, int y, int w, int h, const QPen& pen )
{
  QPainter painter(&d->pixmap_);
  painter.setPen(pen);
  painter.drawRect(x, y, w, h);
}

void KCanvas::drawRect( int x, int y, int w, int h, int color )
{
  QPainter painter(&d->pixmap_);
  const int selectionColor = color ^ 0xFFFFFF;
  painter.setPen(selectionColor);
  painter.drawRect(x, y, w, h);
}

void KCanvas::drawSelectionRect( int x, int y, int w, int h, int color )
{
  QPainter painter(viewport());
  // Emulate XOR on white background
  const int selectionColor = color ^ 0xFFFFFF;
  painter.setPen(selectionColor);
  painter.drawRect(x, y, w, h);
}

void KCanvas::drawPixmap( int x, int y, int w, int h,
                          const QPixmap& image )
{
  const QRect rect = QRect(x, y, w, h);
  QPainter painter(&d->pixmap_);
  painter.drawPixmap(rect, image);
}

void KCanvas::setRepaintProc( RepaintProc_t repaint )
{
  repaintCB_ = repaint;
}

void KCanvas::setEventProc(EventProc_t event)
{
  if( d->eventCB_ )
    removeEventFilter( this );

  d->eventCB_ = event;

  if( d->eventCB_ )
    installEventFilter( this );
}

bool KCanvas::eventFilter( QObject* object, QEvent* event )
{
  if( ( event->type() == QEvent::MouseButtonPress )
      || (event->type() == QEvent::MouseButtonRelease )
      || ( event->type() == QEvent::MouseButtonDblClick )
      || ( event->type() == QEvent::MouseMove ) )
    {
      QMouseEvent* mouseEvent = (QMouseEvent*)event;

	  KEvent::Action action = KEvent::ACTION_SELECT;

	  if (event->type() == QEvent::MouseMove)
	  {
		if (mouseEvent->state() == Qt::LeftButton)
		 {
		  	action = KEvent::LOC_DRAG;
		 }
	  	else
	  	 {
	  		return Q3ScrollView::eventFilter(object, event);
		 }
	   }

      KEvent kevent( action,
                     ( event->type() == QEvent::MouseButtonPress ?
                       KEvent::MOUSE_ACTION_DOWN
                       : ( event->type() == QEvent::MouseButtonRelease ?
                           KEvent::MOUSE_ACTION_UP
                           : KEvent::MOUSE_ACTION_DOUBLECLICK ) ),
                     ( mouseEvent->button() == Qt::LeftButton?
                       KEvent::MOUSE_BUTTON_LEFT
                       : ( mouseEvent->button() == Qt::RightButton ?
                           KEvent::MOUSE_BUTTON_RIGHT
                           : KEvent::MOUSE_BUTTON_MIDDLE ) ),
                     mouseEvent->x(),
                     mouseEvent->y() );
      if( d->eventCB_ )
        d->eventCB_( this, & kevent );
    }

  return Q3ScrollView::eventFilter(object, event);
}

// This is the "paintEvent" for the canvas.
void KCanvas::drawContents( QPainter*, int, int, int, int )
{
  // All the drawing methods have drawn into d->pixmap_.

  // Now blit it to the screen
  QPainter painter(viewport());
  painter.translate(-contentsX(), -contentsY());
  // TODO optimization: use the clipping arguments
  painter.drawPixmap(0, 0, d->pixmap_);

  // This callback is now used for painting -additional- stuff, like selection.
  painter.translate(contentsX(), contentsY());
  if( repaintCB_ )
    (*repaintCB_)( this );
}

void KCanvas::drawContents( QPainter* )
{
  // Empty - Just to avoid compiler warning
}

void KCanvas::removeContents( )
{
  QObjectList content = this->children();
  if(!content.isEmpty()) {
    for(int i = 0;i<content.count(); ++i) {
      delete content.at(i);
    }
  }
}

void KCanvas::reparent(QWidget * parent, const QPoint & p, bool showIt)
{
    if(KFrame * frame = dynamic_cast<KFrame *> (parent))
    {
      Q3ScrollView* scrollView = frame->qScrollView();
        if(!scrollView)
            QWidget::reparent(frame, p, showIt);
        else
	  {
            QWidget::reparent(scrollView->viewport(), p, showIt);
	    scrollView->addChild(this,this->x(),this->y());
	  }
    }
    else
        QWidget::reparent(parent,p,showIt);
}

void KCanvas::reparent(QWidget * parent, Qt::WFlags f, const QPoint & p, bool showIt)
{
    QWidget::reparent(parent, f, p, showIt);
}

void KCanvas::resizeContents(int width, int height)
{
    // Resize both the canvas contents, and the pixmap for it
    Q3ScrollView::resizeContents(width, height);

    const QSize wantedSize(width, height);
    if (d->pixmap_.size() != wantedSize) {
	d->pixmap_ = QPixmap(wantedSize);
	d->pixmap_.fill(Qt::white);
    }
}

void KCanvas::clear()
{
    d->pixmap_.fill(Qt::white);
}

void KCanvas::setWidth(int width)
{
    this->resize( (width > 0)? width : this->parentWidget()->width(), this->height() );
}

void KCanvas::setColors(int fg, int bg)
{
    this->viewport()->setPaletteForegroundColor(QColor(fg));
    this->viewport()->setPaletteBackgroundColor(QColor(bg));
    QPalette palette = this->palette();
    palette.setColor(this->backgroundRole(), QColor(bg));
    this->setPalette(palette);
}

QFont KCanvas::findFont() const
{
    return this->font();
}

QFont KCanvas::findBoldFont() const
{
    QFont font = this->font();
    font.setBold(true);
    return font;
}

QFont KCanvas::selectFont(int bold, int /*size*/) const
{
    QFont font = this->font();
    font.setBold(bold);
    //font.setPointSize(size);
    return font;
}
Please reimplement this class for pure Qt4 ( you can do this wit assumption that KFrame inherits from QWidget and KEvent from QEvent, KItem could be ommitted)