<br><br><div class="gmail_quote">On Thu, Oct 14, 2010 at 3:31 PM, Yihui Xie <span dir="ltr">&lt;<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>&gt;</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 &lt;- function(p, text) {<br>
  extents &lt;- qtextExtents(p, text)<br>
  nlines &lt;- sapply(gregexpr(&#39;\\n&#39;, text), function(xx) ifelse(any(xx &lt;<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&#39;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 &lt;<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>&gt;<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 &lt;<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; We can calculate the width of a string inside the paintFun(layer,<br>
&gt; painter) since qstrWIdth() needs the &#39;painter&#39; argument. I wonder if<br>
&gt; we can calculate the width when we only have the layer object, e.g.<br>
&gt;<br>
&gt; s &lt;- qscene()<br>
&gt; test_layer &lt;- qlayer(s, function(layer, painter) {<br>
&gt;    qdrawRect(painter, 10, 10, 90, 90, stroke = &#39;blue&#39;)<br>
&gt;    qstrWidth(painter, &#39;this is a string&#39;)<br>
&gt; }, limits=qrect(0,0,100,100))<br>
&gt; ## what if we are outside?<br>
&gt; qstrWidth(??, &#39;this is a string&#39;)<br>
&gt;<br>
&gt; I want to automatically adjust the plot margins according to the width<br>
&gt; and height of axis labels. Is there any way to calculate the height of<br>
&gt; a string?<br>
&gt;<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;">


&gt; Thanks!<br>
&gt;<br>
&gt; Regards,<br>
&gt; Yihui<br>
&gt; --<br>
&gt; Yihui Xie &lt;<a href="mailto:xieyihui@gmail.com" target="_blank">xieyihui@gmail.com</a>&gt;<br>
&gt; Phone: 515-294-2465 Web: <a href="http://yihui.name" target="_blank">http://yihui.name</a><br>
&gt; Department of Statistics, Iowa State University<br>
&gt; 2215 Snedecor Hall, Ames, IA<br>
&gt;<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>