View Full Version : Amateur Qt question about movement of an object

17th April 2009, 21:20
Hello, I'm new here, and I know that I'm probably gonna sound lame, but... I have some urgent homework to finish.

So it's basically billiards in Qt. Our teacher made an example of moving circles in Java, so I tried to adapt parts of the code from Java to C++ in Qt.

So I basically have two classes besides the billiards class in Qt.

I'm sorry it's in spanish but you basically get the idea from the code.

So, what I'm basically doing with bola.h (ball) is a class to create a ball (just the object) with coordinates x and y for center, and radio for radius.

DX and DY are the directions in X and Y.

BolaVisual (VisualBall) is a class to represent graphically the ball and make some functions about its movement. My problem is that I haven't been able to represent the ball graphically in the main window. And I still have to make it move and bounce back when it hits either the borders of the green square or other balls.

The balls that appear when you Run the thing are just drawEllipse's of how the thing should look.

Can you guys help me with the display problem and the movement? I just need it to move in straight lines I mean... The direction change is already programmed in the bolaVisual.cpp I think.

Any help would be appreciated. I attached the .cpp's, the .h's and the .pro

Thanks in advance!

19th April 2009, 10:12
You should use QGraphicsView for visualization instead of making each object a widget. Your ball class would then inherit QGraphicsEllipseItem or QGraphicsItem instead of QWidget.