PDA

View Full Version : Can't draw an arc with Qt on a beaglebone



thenewnewguy
27th November 2014, 23:14
I'm using Qt Creator to design a GUI for an industrial machinery. The beaglebone displays various things based on CAN messages it receives. All was going well until I tried to draw an arc to symbolize the position of some moving equipment.

Using Qt Creator's UI editor, I've placed a square shaped graphics view in my UI. I gave it a width of 256 and a height of 256 and I named it graphicsPipeView.

In mainwindow.cpp:


PipeScene = new QGraphicsScene;
ui->graphicsPipeView->setScene(PipeScene);
QRectF pipe_rect(0, 0, 250, 250);
QRectF inner_rect(10, 10, 230, 230);
PipeScene->addEllipse(pipe_rect, QPen(QColor(0, 0, 0)), QBrush(QColor(230, 230, 230))); // this draws the circle in the picture
QPainterPath *path = new QPainterPath();

path->moveTo(0, 0);
path->lineTo(250, 250); // this draws the NW to SE line - I drew this as a sanity check because I couldn't get the arc to draw
path->moveTo(250, 0);
path->lineTo(0, 250); // this draws the NE to SW line - I also drew this as a sanity check because I couldn't get the arc to draw
path->arcMoveTo(inner_rect, 90);
path->lineTo(125, 125); // this draws the horizontal line, but according to the arcMoveTo command, it should be vertical (at least I think that's what it's supposed to be)
path->closeSubpath();
PipeScene->addPath(*path);
ui->graphicsPipeView->show();

Here's my problem. I couldn't draw ANY arc at all so I decided to see where or how the code was failing. I came up with the above test. The resulting picture is attached.

According to the documentation, arcMoveTo(inner_rect, 90) should move the starting point to 12 noon if the drawing was a clock. The lineTo(125, 125) should draw a vertical line. Only problem is the line is horizontal. I can put any number (degrees) in the arcMoveTo() function and the resulting line is always as shown.

What am I doing wrong? I've tried many iterations of an arcMoveTo() followed by an arcTo() but the result is either a point or a random-angled line.

Both my Linux laptop and the beaglebone are running Qt version 4.8.1.

anda_skoa
28th November 2014, 06:02
So you are saying it works when the program runs on your laptop but does not work when it runs on the beagleboard?

Cheers,
_

thenewnewguy
28th November 2014, 18:20
Sorry for the confusion. What I meant is that I'm cross-compiling for a beaglebone on my laptop using the Qt Creator suite. I'm not running the program on my laptop. I can't seem to get the arc related functions to work properly.

anda_skoa
29th November 2014, 09:53
Have you tried specifying a rect that actually intersects with the position you are on when you start the arc?

Cheers,
_

thenewnewguy
1st December 2014, 22:55
Don't know what you mean. From my reading of the documentation arcMoveTo() sets the starting point of the arc based on an ellipse/circle defined by the rectangle you pass to it, along with the starting angle you specify. From what I've read it doesn't care what position the pen was previously at before you started to draw the arc.

And yes, I've tried changing the order of the drawing commands. Even if the arcMoveTo() comes first, I get the same result.

anda_skoa
2nd December 2014, 07:40
Hmm.
My interpretation is that a moveTo needs to be able to follow a patch from the current position to the target position along the geometry specified.

If the geometry and the current position do not intersect, where would it start?

But to rule out that this is in fact a necessary pre-condition I suggested to check if it works if the arc's ellipse contains the current position

Cheers,
_