[RQt-devel] qstrWidth() outside the paintFun()
Michael Lawrence
lawrence.michael at gene.com
Fri Oct 15 03:51:36 CEST 2010
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/0c96c4b8/attachment.htm>
More information about the Qtinterfaces-devel
mailing list