Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smoothing an inclined line

Tags:

c++

lines

qt

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:

enter image description here

It's awful! The only beautiful lines I can draw are horizontal, vertical or 45° inclined ones...

like image 233
Getter Avatar asked Aug 21 '17 15:08

Getter


People also ask

What is smooth inclined plane?

A smooth inclined plane is inclined at an angle theta with the horizontal. A body starts from rest and slides down the inclined surface.

How do you resolve forces on an inclined plane?

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.

How do you find acceleration on a smooth inclined plane?

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.

How to get the resultant in inclined plane?

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.


1 Answers

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);
like image 166
csunday95 Avatar answered Sep 22 '22 12:09

csunday95