I have no idea what you mean by "resize my paintEvent".
Resizing the window should not influence your drawing code in any way. Your canvas is simply larger. If you mean that you wish to scale the contents then use QPainter::setWindow(), QPainter::setViewport() and QPainter::worldTransform() (the latter can be used to map mouse event coordinates to what you specify by setWindow()).
The most trivial approach would be something along:
m_points <<
QPointF(100*meF.
x()/(qreal
)width
(),
100*meF.
y()/(qreal
)height
());
update();
}
p.setViewport(rect());
p.
setWindow(QRect(0,
0,
100,
100));
foreach
(QPointF pt, m_points
) p.
drawPoint(pt
);
}
void X::mousePressEvent(QMouseEvent *me) {
QPointF meF = me->pos();
m_points << QPointF(100*meF.x()/(qreal)width(), 100*meF.y()/(qreal)height());
update();
}
void X::paintEvent(QPaintEvent *pe) {
QPainter p(this);
p.setViewport(rect());
p.setWindow(QRect(0,0,100,100));
foreach(QPointF pt, m_points) p.drawPoint(pt);
}
void X::resizeEvent(QResizeEvent*) { update(); }
To copy to clipboard, switch view to plain text mode
Bookmarks