[RQt-devel] layout issues

Michael Lawrence lawrence.michael at gene.com
Tue Oct 5 20:07:23 CEST 2010


Looked a bit into the layout issues. I've found that the following script
gives a fairly desirable result. Forget about the stretch factor stuff for
now, because unless a maximum or fixed size is set for a row/column, there
is no guarantee that the row/column will not expand.

library(qtpaint)

fill_painter <- function(color) {
  function(item, painter) qdrawRect(painter, 0, 0, 1, 1, fill = color)
}

layout_layer <- function(Color, ...) {
  qlayer(figLayer, fill_painter(Color), limits = qrect(0, 0, 1, 1), ...)
}

scene <- qscene()
figLayer <- qlayer(scene)
layout <- figLayer$gridLayout()

titleLayer <- layout_layer("red", colSpan = 2)
yaxisLayer <- layout_layer("blue", row = 1)
plotLayer <- layout_layer("green", row = 1, col = 1)
xaxisLayer <- layout_layer("yellow", row = 2, col = 1)

## Set the maximum widths/heights:

layout$setRowMaximumHeight(0, 50)
layout$setColumnMaximumWidth(0, 50)
layout$setRowMaximumHeight(2, 50)

## Could use Preferred here, with stretch factor set to zero, but this
## breaks when a layer spans multiple cells. It is hard to say if this
## is a bug in Qt, since QGraphicsGridLayout is largely
## undocumented. QGridLayout says a stretch-zero row/column can grow
## when no other row/column can grow. Setting a fixed or minimum
## width/height probably sets undue restrictions on the layout. The
## user should be able to shrink the window down, even if it is not
## longer possible to draw the data effectively. Thus, it's probably
## best to set the maximum.

## It is probably cleaner to set the dimensions directly on the layer:
## titleLayer$setMaximumHeight(50)
## xaxisLayer$setMaximumHeight(50)
## yaxisLayer$setMaximumWidth(50)
## But this currently crashes due to a (reported) bug in Smoke.

qplotView(scene)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/qtinterfaces-devel/attachments/20101005/7969a192/attachment.htm>


More information about the Qtinterfaces-devel mailing list