<br><br><div class="gmail_quote">On Thu, Oct 14, 2010 at 8:00 PM, Yihui Xie <span dir="ltr"><<a href="mailto:xieyihui@gmail.com">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;">
Yes, I found the height calculated from qtextExtents() is only a<br>
height for one line, and that's why I especially dealt with '\n'.<br>
<br></blockquote><div><br>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. <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;">
I often feel drowned in Qt docs, partly because I know little about<br>
C++, and there are too many unfamiliar concepts. I even thought<br>
sizeHint is something like tooltips (hints?)...<br>
<br></blockquote><div><br>But it's got to be a lot more accessible than say R's docs.<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;">
So which way do you recommend to adjust the spacing of axis layers?<br>
Currently it seems only maximum height/width work well.<br>
<div class="im"><br></div></blockquote><div><br>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).<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;"><div class="im">
Regards,<br>
Yihui<br>
--<br>
Yihui Xie <<a href="mailto:xieyihui@gmail.com">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>
</div><div><div></div><div class="h5">On Thu, Oct 14, 2010 at 8:51 PM, Michael Lawrence<br>
<<a href="mailto:lawrence.michael@gene.com">lawrence.michael@gene.com</a>> wrote:<br>
><br>
><br>
> On Thu, Oct 14, 2010 at 3:31 PM, Yihui Xie <<a href="mailto:xieyihui@gmail.com">xieyihui@gmail.com</a>> wrote:<br>
>><br>
>> And can we just put an approximate solution for qstrHeight() for the time<br>
>> 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>
><br>
> Do you really need to multiply by the nlines here? If so, that's a bug, as<br>
> QFontMetrics is supposed to figure that out.<br>
><br>
>><br>
>> Regards,<br>
>> Yihui<br>
>> --<br>
>> Yihui Xie <<a href="mailto:xieyihui@gmail.com">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">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>
><br>
> In which coordinate system? The painter is used for transforming from pixels<br>
> (how QFontMetrics returns the dimensions) to the data coordinates.<br>
><br>
> Most likely what you want are scene coordinates though, for sizing the<br>
> layer. Perhaps you could come up with a function for mapping the text bounds<br>
> through a transform from the view coordinates (pixels, as provided by<br>
> QFontMetrics) to scene coordinates.<br>
><br>
> That will break down when multiple views are involved, but then again, so<br>
> 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<br>
> automatically requests enough space to show its text contents. The<br>
> sizeHintFun is meant for this. The interpretation of the size hint depends<br>
> on the size policy. With the correct policy, it can communicate the minimum<br>
> width/height needed by the layer, which the grid layout *should* satisfy.<br>
> 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>
><br>
>><br>
>> > Thanks!<br>
>> ><br>
>> > Regards,<br>
>> > Yihui<br>
>> > --<br>
>> > Yihui Xie <<a href="mailto:xieyihui@gmail.com">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">Qtinterfaces-devel@lists.r-forge.r-project.org</a><br>
>><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>
><br>
><br>
</div></div></blockquote></div><br>