I can't find a proper way to draw a smooth inclined line without having it over-pixelated in Qt with the QPainterPath
object.
Note that I know it doesn't make sense to draw the path in the paintEvent
function, I put it there for sake of simplicity. I'm trying to draw the line directly in the central widget.
Hereafter is a snippet of my code:
void MyObject::paintEvent(QPaintEvent *)
{
QPainterPath aPath;
aPath.moveTo(40.0, 60.0); //random values to try
aPath.lineTo(254, 354.0);
QPainter painter(this);
painter.setPen(QPen(QColor(20, 20, 200), 10, Qt::SolidLine));
painter.drawPath(aPath);
}
And here is the result I get:
It's awful! The only beautiful lines I can draw are horizontal, vertical or 45° inclined ones...
A smooth inclined plane is inclined at an angle theta with the horizontal. A body starts from rest and slides down the inclined surface.
In the case of inclined planes, we resolve the weight vector (Fgrav) into two components. The force of gravity will be resolved into two components of force – one directed parallel to the inclined surface and the other directed perpendicular to the inclined surface.
If we call the angle of inclination of our smooth plane 𝜃, then 𝑎, the acceleration, is equal to 𝑔 times the sin of 𝜃. The point here is that acceleration is constant because 𝑔 and 𝜃 are constant.
The resultant force on a body on an inclined plane, ⃑ 𝐹 , is the sum of ⃑ 𝑅 and 𝑊 . We can express this as 𝐹 = 𝑅 + 𝑚 𝑔 . The direction of ⃑ 𝐹 is downward, parallel to the plane. Let us look at an example of a body on an inclined surface in which the acceleration of the body parallel to the surface is determined.
If you are looking for drawing quality, the Qt documentation provides an illustrative example (5.X version) of the use of its render quality flags. Generally, you can use the flags specified here (5.X version), and set them using the QPainter::setRenderHint()
(5.X version) function. See if you are able to achieve the desired quality using those methods. For your code, you'd be looking for something like
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.setPen(QPen(QColor(20, 20, 200), 10, Qt::SolidLine));
painter.drawPath(aPath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With