[RQt-devel] qstrWidth() outside the paintFun()
Yihui Xie
xieyihui at gmail.com
Fri Oct 15 05:00:50 CEST 2010
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 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?)...
So which way do you recommend to adjust the spacing of axis layers?
Currently it seems only maximum height/width work well.
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
>
>
More information about the Qtinterfaces-devel
mailing list