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.
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.