[RQt-devel] par(xpd=NA) and the layout approach in qtpaint

Michael Lawrence lawrence.michael at gene.com
Wed Sep 1 16:07:04 CEST 2010


On Tue, Aug 31, 2010 at 10:11 PM, Yihui Xie <xie at yihui.name> wrote:

> Hi all,
>
> I'm wondering if there are any approaches to completely show the
> graphical elements on the boundaries under a layout containing several
> layers. This is like the functionality par(xpd=NA) in base R graphics.
> See the example below that the texts for the origin (0,0) on the axes
> are partially hidden.
>
> My another problem is, I don't really understand the layout approach,
> although I've been reading the qtpaint vignette and digging the Nokia
> Qt documentations.


Me neither. I'll try to find some time to look into it. The QGraphicsLayout
stuff is even worse than QLayout. You're correct that stretch factory set to
zero does not work. I inferred that from the QGridLayout, but it must be
different for QGraphicsGridLayout.

I'd like to move to an approach where each layer has a size and sizing
policy, rather than doing things by rows and columns in the grid layout. I
haven't figured out that yet though either.

Michael


> Specifically, how should we define the coordinate
> system in each layer in a layout? (I experimented with mouse clicking
> to get locations but got even more confused) With a single layer, I
> can plot the data using its range to define the limits and everything
> is fine. Besides, does anyone have a working demo to draw a simplest
> plot with the layout approach? I struggled with
> set(Column|Row)(Maximum|Minimum|Preferred)(Width|Height) and
> set(Column|Row)StretchFactor, but they do not behave as we expect them
> to, e.g. the stretch factor being 0 will not restrict the height/width
> of a layer to be a fixed value -- they change as we resize the window.
>
> Below is the R code:
>
> # I need hints on how to split the root layer into several regions
> # and what are their coordinate systems
> library(qtpaint)
> scene = qscene()
> figLayer = qlayer(scene,limits=qrect(0,0,675,550))
> titlePainter = function(item, painter) {
>    qdrawText(painter, 'The Useless Title', 300, 0,'center','bottom')
>    tmp=as.matrix(titleLayer$boundingRect())
>    qdrawRect(painter, tmp[1,1],tmp[1,2],tmp[2,1],tmp[2,2])
> }
> yAxisPainter = function(item, painter) {
>    qdrawText(painter, as.character(pretty(1:400)), 37.5, pretty(1:400))
> }
> plotPainter = function(item, painter) {
>    qdrawPoint(painter, runif(1000, 0, 600), runif(1000, 0, 400))
>    qdrawRect(painter, 1, 1, 600-1, 400-1)
> }
> xAxisPainter = function(item, painter) {
>    qdrawText(painter, as.character(pretty(1:600)), pretty(1:600), 37.5)
> }
> mouseLocator = function(item, event){
>    print(as.numeric(event$pos()))
> }
> titleLayer = qlayer(figLayer, titlePainter,
> mousePressFun=mouseLocator, row=2,col=1)
> yaxis = qlayer(figLayer, yAxisPainter,mousePressFun=mouseLocator,row =
> 1,col=0)
> plotLayer = qlayer(figLayer, plotPainter,
> mousePressFun=mouseLocator,row = 1, col = 1)
> xaxis = qlayer(figLayer, xAxisPainter, mousePressFun=mouseLocator,row
> = 0, col = 1)
>
> layout = figLayer$gridLayout()
>
> layout$setRowMaximumHeight(0, 75)
> layout$setRowMinimumHeight(0, 60)
> # main plot region: 400x600
> layout$setRowPreferredHeight(1, 400)
> layout$setRowMaximumHeight(2, 75)
> layout$setRowMinimumHeight(2, 60)
>
> layout$setColumnMaximumWidth(0, 75)
> layout$setColumnMinimumWidth(0, 60)
> layout$setColumnPreferredWidth(1, 600)
> layout$setRowStretchFactor(0, 0)
> layout$setRowStretchFactor(1, 1)
> layout$setRowStretchFactor(2, 0)
> layout$setColumnStretchFactor(0, 0)
> layout$setColumnStretchFactor(1, 1)
>
> print(view<-qplotView(scene = scene))
>
>
> #################################################
>
> > sessionInfo()
> R version 2.11.1 (2010-05-31)
> x86_64-pc-linux-gnu
>
> locale:
> [1] en_US.utf8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] qtpaint_0.7.9
>
> loaded via a namespace (and not attached):
> [1] qtbase_0.8-4 tools_2.11.1
>
>
> Thanks a lot!
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-6609 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 3211 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/20100901/8cc7368a/attachment.htm>


More information about the Qtinterfaces-devel mailing list