[Interest] scaling QRect inside a QWidget

Nye kshegunov at gmail.com
Fri Mar 4 09:29:11 CET 2016


Hello Nicolas,
> just scaling the widget don't resize the QRect
I don't see a reason this should happen automatically, you're supposed to
scale your rect yourself.

> But first, since widths are int, I have to make a conversion to float
then to int, who brings some rounding errors.
This is expected, you can't keep precision when truncating from floating
point to integers. However, the errors are in the range of +-1, so in most
cases this shouldn't be a problem.

> And for some reason when I pass the value my QRect doesn't get the good
value (note that, this may comes from our code).
Possibly an error in your code, try debugging it and tracing the reason for
that.

> But I try to figure if there is another way than computing width, height,
new position of the QRect.
You could use QRectF, which employs floating point coordinates, if that
suits you better.

Kind regards,
Konstantin.


On Fri, Mar 4, 2016 at 3:28 AM, Nicolas Jäger <jagernicolas at legtux.org>
wrote:

> Hi Nye and others,
>
> I use the resize event, the problem is how can I scale properly the QRect,
> because just scaling the
> widget don't resize the QRect. I try to compute the ratio =
> newWidth/oldWidth of widget then doing
> newWidthOfQRect * ratio. But first, since widths are int, I have to make a
> conversion to float then
> to int, who brings some rounding errors.
>
> And for some reason when I pass the value my QRect doesn't get the good
> value (note that, this may
> comes from our code). But I try to figure if there is another way than
> computing width, height, new
> position of the QRect.
>
> Regards,
> Nicolas
>
>
>
> > You could intercept the QWidget's resize event either by providing an
> > override (http://doc.qt.io/qt-5/qwidget.html#resizeEvent) or by
> installing
> > an event filter (
> http://doc.qt.io/qt-5/eventsandfilters.html#event-filters).
> > Note, however, you'll receive a resize event on initialization of the
> > widget as well.
> >
> > Kind regards.
> >
> > On Fri, Mar 4, 2016 at 2:11 AM, Nicolas Jäger <jagernicolas at legtux.org>
> > wrote:
> >
> > > Hi,
> > >
> > > I have a QRect inside a QWidget and I would like to scale it when the
> > > widget is scaled by the user.
> > > There is a QtThing to do that ?
> > >
> > > regards,
> > > Nicolas
> > > _______________________________________________
> > > Interest mailing list
> > > Interest at qt-project.org
> > > http://lists.qt-project.org/mailman/listinfo/interest
> > >
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160304/4d9dd4df/attachment.html>


More information about the Interest mailing list