<br><br><div class="gmail_quote">On Thu, Oct 14, 2010 at 3:31 PM, Yihui Xie <span dir="ltr"><<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
And can we just put an approximate solution for qstrHeight() for the time being?<br>
<br>
qstrHeight <- function(p, text) {<br>
extents <- qtextExtents(p, text)<br>
nlines <- sapply(gregexpr('\\n', text), function(xx) ifelse(any(xx <<br>
0), 0, length(xx)) + 1)<br>
nlines * (extents[,4] - extents[,2])<br>
}<br>
<br></blockquote><div><br>Do you really need to multiply by the nlines here? If so, that's a bug, as QFontMetrics is supposed to figure that out.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Regards,<br>
Yihui<br>
--<br>
Yihui Xie <<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>><br>
Phone: 515-294-2465 Web: <a href="http://yihui.name" target="_blank">http://yihui.name</a><br>
Department of Statistics, Iowa State University<br>
2215 Snedecor Hall, Ames, IA<br>
<br>
<br>
<br>
On Thu, Oct 14, 2010 at 11:49 AM, Yihui Xie <<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> We can calculate the width of a string inside the paintFun(layer,<br>
> painter) since qstrWIdth() needs the 'painter' argument. I wonder if<br>
> we can calculate the width when we only have the layer object, e.g.<br>
><br>
> s <- qscene()<br>
> test_layer <- qlayer(s, function(layer, painter) {<br>
> qdrawRect(painter, 10, 10, 90, 90, stroke = 'blue')<br>
> qstrWidth(painter, 'this is a string')<br>
> }, limits=qrect(0,0,100,100))<br>
> ## what if we are outside?<br>
> qstrWidth(??, 'this is a string')<br>
><br>
> I want to automatically adjust the plot margins according to the width<br>
> and height of axis labels. Is there any way to calculate the height of<br>
> a string?<br>
><br></blockquote><div><br>In which coordinate system? The painter is used for transforming from pixels (how QFontMetrics returns the dimensions) to the data coordinates. <br><br>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. <br>
<br>That will break down when multiple views are involved, but then again, so would the concept of having a plot with axes, etc.<br><br>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.<br>
<br>Anyway, let me know if you need more information. The Qt docs are helpful.<br><br>Michael<br><br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
> Thanks!<br>
><br>
> Regards,<br>
> Yihui<br>
> --<br>
> Yihui Xie <<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>><br>
> Phone: 515-294-2465 Web: <a href="http://yihui.name" target="_blank">http://yihui.name</a><br>
> Department of Statistics, Iowa State University<br>
> 2215 Snedecor Hall, Ames, IA<br>
><br>
_______________________________________________<br>
Qtinterfaces-devel mailing list<br>
<a href="mailto:Qtinterfaces-devel@lists.r-forge.r-project.org" target="_blank">Qtinterfaces-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel</a><br>
</blockquote></div><br>