Hi! I'm trying to write the application that will:
1) in the beginning draw an ellipse in the centre of a widget
2) then draw the second ellipse and make it move
Of course this is only the part of something bigger (there will be much more ellipses), but now I have the problem to make this second ellipse move. I'm trying to remember the coordinates of the ellipse in the list and change them in the loop. And after each change of the coordinates I want the application to sleep and repaint the widget. I want to make it sleep because it's the one of the ways to make the move of the ellipse visible. I tried various methods, but unfortunately, nothing worked. I launch the application, and no move is visible - I can see only the last position of the ellipse. Could anyone help me? Thanks in advance! There is the part of my code:
painter.setBrush(Qt::SolidPattern);
for(int i = 0; i < pointsList.size(); i++) {
painter.
drawEllipse(QRect(pointsList.
at(i
),
*(getRadius
())));
}
}
void RightWindow::start(double x, double y) {
setNewX(x);
setNewY(y);
pointsList.
append(QPoint(getNewX
(), getNewY
()));
repaint();
setNewX(x - 10);
setNewY(y - 10);
pointsList.
append(QPoint(getNewX
(), getNewY
()));
repaint();
for(int i = 0; i < 10; i++) {
QPoint point
= pointsList.
at(pointsList.
size() - 1);
point.setX(point.x() + 2);
pointsList.removeAt(pointsList.size() - 1);
pointsList.append(point);
QTimer::singleShot(1000,
this,
SLOT(repaint
()));
repaint();
}
}
void RightWindow::paintEvent(QPaintEvent* event) {
QPainter painter(this);
painter.setBrush(Qt::SolidPattern);
for(int i = 0; i < pointsList.size(); i++) {
painter.drawEllipse(QRect(pointsList.at(i), *(getRadius())));
}
}
void RightWindow::start(double x, double y) {
setNewX(x);
setNewY(y);
pointsList.append(QPoint(getNewX(), getNewY()));
repaint();
setNewX(x - 10);
setNewY(y - 10);
pointsList.append(QPoint(getNewX(), getNewY()));
repaint();
for(int i = 0; i < 10; i++) {
QPoint point = pointsList.at(pointsList.size() - 1);
point.setX(point.x() + 2);
pointsList.removeAt(pointsList.size() - 1);
pointsList.append(point);
QTimer::singleShot(1000, this, SLOT(repaint()));
repaint();
}
}
To copy to clipboard, switch view to plain text mode
RightWindow class is my class that inherits after QWidget. And the methods such as getNewX() are my own method written by me...
Bookmarks