PDA

View Full Version : QPointF - draw only 30% of window



pajczur
18th May 2017, 23:56
Hello,
I wonder. "Width" of QWidget is in what resolution?
I mean:


ui::QWidget::width()

It will return value in what units?

I have code that dinamically draws (by QPainter) QPointF (many of them).
And for my horizontal coordinate I have that code:


QPointF point;

for(int i=1; i<something; i++)
{
point.setX(i);
}

And my aim is to use "something" as a resolution. So for example: no matter how big is "something", my points always fill evenly for example 30% of my widget. But that doesn't work:

ui::QWidget::width() * 0.3

Because QPointF is in different units than widget width.

d_stranz
19th May 2017, 18:38
A QWidget's width and height are always in pixel units. The mapping from QPainter coordinates to QWidget coordinates is one-to-one in pixels unless you have applied a scaling transformation to the QPainter.

Your code makes no sense. The for() loop repeatedly sets the x value, and when it exits, point.x() will always have the last value of i (that is, "something" - 1). And if "something" is capped at 30% of the width (converted to an integer, since "i" is an int), the last x that is assigned will be 30% of the width.

pajczur
20th May 2017, 14:26
OK, I'm sorry, I was wrong in some way, I don't understand why, because now everything works fine for me.
And great thanks for your reply