One more feature, sorry to extend in the same question but it's because the context has already been set.
In order to implement scaling on the wheel event I did the following:
void
{
scaleFactor += ((float)event->delta()/1200.0);
update();
}
void
LT_DrawingCanvas::wheelEvent(QWheelEvent *event)
{
QWidget::wheelEvent(event);
scaleFactor += ((float)event->delta()/1200.0);
update();
}
To copy to clipboard, switch view to plain text mode
and in the paintEvent:
void
{
p.scale(scaleFactor, scaleFactor);
p.drawPixmap(0, 0, m_base);
p.drawImage(0, 0, m_mask);
}
void
LT_DrawingCanvas::paintEvent(QPaintEvent *pe)
{
QPainter p(this);
p.scale(scaleFactor, scaleFactor);
p.drawPixmap(0, 0, m_base);
p.drawImage(0, 0, m_mask);
}
To copy to clipboard, switch view to plain text mode
My widget hierarchy is as below:
Mainwindow
- Grid Layout
- Scrollarea
- MyCustomDrawing Canvas Widget (created just like the code wysota suggested above)
I am not getting the scrollbars on scaling the image. I realize I am drawing the scaled image again, instead of resizing the widget. I tried using resize on the widget but it didn't work. What I am doing wrong ?
Bookmarks