[RQt-devel] qstrWidth() outside the paintFun()

Michael Lawrence lawrence.michael at gene.com
Fri Oct 15 06:37:08 CEST 2010


On Thu, Oct 14, 2010 at 8:00 PM, Yihui Xie <xieyihui at gmail.com> wrote:

> Yes, I found the height calculated from qtextExtents() is only a
> height for one line, and that's why I especially dealt with '\n'.
>
>
I will need to look into that. In my quick tests, QFontMetrics::boundingRect
seems to work fine with \n, and that's what the Painter uses.


> I often feel drowned in Qt docs, partly because I know little about
> C++, and there are too many unfamiliar concepts. I even thought
> sizeHint is something like tooltips (hints?)...
>
>
But it's got to be a lot more accessible than say R's docs.


> So which way do you recommend to adjust the spacing of axis layers?
> Currently it seems only maximum height/width work well.
>
>
I will look into the effect of sizeHint. In the meantime, you could just set
the maximum dimensions to what you get from QFontMetrics::boundingRect,
since at least in your case there is no view transform (and thus the scene
and screen coordinates are the same).

Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
>
> On Thu, Oct 14, 2010 at 8:51 PM, Michael Lawrence
> <lawrence.michael at gene.com> wrote:
> >
> >
> > On Thu, Oct 14, 2010 at 3:31 PM, Yihui Xie <xieyihui at gmail.com> wrote:
> >>
> >> And can we just put an approximate solution for qstrHeight() for the
> time
> >> being?
> >>
> >> qstrHeight <- function(p, text) {
> >>  extents <- qtextExtents(p, text)
> >>  nlines <- sapply(gregexpr('\\n', text), function(xx) ifelse(any(xx <
> >> 0), 0, length(xx)) + 1)
> >>  nlines * (extents[,4] - extents[,2])
> >> }
> >>
> >
> > Do you really need to multiply by the nlines here? If so, that's a bug,
> as
> > QFontMetrics is supposed to figure that out.
> >
> >>
> >> Regards,
> >> Yihui
> >> --
> >> Yihui Xie <xieyihui at gmail.com>
> >> Phone: 515-294-2465 Web: http://yihui.name
> >> Department of Statistics, Iowa State University
> >> 2215 Snedecor Hall, Ames, IA
> >>
> >>
> >>
> >> On Thu, Oct 14, 2010 at 11:49 AM, Yihui Xie <xieyihui at gmail.com> wrote:
> >> > Hi,
> >> >
> >> > We can calculate the width of a string inside the paintFun(layer,
> >> > painter) since qstrWIdth() needs the 'painter' argument. I wonder if
> >> > we can calculate the width when we only have the layer object, e.g.
> >> >
> >> > s <- qscene()
> >> > test_layer <- qlayer(s, function(layer, painter) {
> >> >    qdrawRect(painter, 10, 10, 90, 90, stroke = 'blue')
> >> >    qstrWidth(painter, 'this is a string')
> >> > }, limits=qrect(0,0,100,100))
> >> > ## what if we are outside?
> >> > qstrWidth(??, 'this is a string')
> >> >
> >> > I want to automatically adjust the plot margins according to the width
> >> > and height of axis labels. Is there any way to calculate the height of
> >> > a string?
> >> >
> >
> > In which coordinate system? The painter is used for transforming from
> pixels
> > (how QFontMetrics returns the dimensions) to the data coordinates.
> >
> > Most likely what you want are scene coordinates though, for sizing the
> > layer. Perhaps you could come up with a function for mapping the text
> bounds
> > through a transform from the view coordinates (pixels, as provided by
> > QFontMetrics) to scene coordinates.
> >
> > That will break down when multiple views are involved, but then again, so
> > would the concept of having a plot with axes, etc.
> >
> > In the long term, it would be best for there to be a Layer that
> > automatically requests enough space to show its text contents. The
> > sizeHintFun is meant for this. The interpretation of the size hint
> depends
> > on the size policy. With the correct policy, it can communicate the
> minimum
> > width/height needed by the layer, which the grid layout *should* satisfy.
> > But who knows.
> >
> > Anyway, let me know if you need more information. The Qt docs are
> helpful.
> >
> > Michael
> >
> >
> >
> >>
> >> > Thanks!
> >> >
> >> > Regards,
> >> > Yihui
> >> > --
> >> > Yihui Xie <xieyihui at gmail.com>
> >> > Phone: 515-294-2465 Web: http://yihui.name
> >> > Department of Statistics, Iowa State University
> >> > 2215 Snedecor Hall, Ames, IA
> >> >
> >> _______________________________________________
> >> Qtinterfaces-devel mailing list
> >> Qtinterfaces-devel at lists.r-forge.r-project.org
> >>
> >>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/qtinterfaces-devel/attachments/20101014/be24f547/attachment-0001.htm>


More information about the Qtinterfaces-devel mailing list