[RQt-devel] How to delete a layout in an existing widget?

Tengfei Yin yintengfei at gmail.com
Tue Apr 12 07:54:22 CEST 2011


Hi Michael,

Thanks,

I am not sure which object should be set to NULL.

> trackWidget <- Qt$QWidget()
> trackLayout <- Qt$QGridLayout()
> trackWidget$setLayout(trackLayout)
NULL
> trackWidget$layout()
QGridLayout instance
> trackWidget$layout() <- NULL
Error in trackWidget$layout() <- NULL :
  invalid (NULL) left side of assignment

The layout() return a instance and it looks like it cannot be set to NULL.

My case may sounds weird, I changed view object to referecne class, say obj
is a view object, obj$pars$seqname <- "chr3", will change the visualized
chromosome and emit a signal to re-create multiple tracks for chr3 , I
actually recreate the scene and view, but only keep the top widget which
contains all tracks, so it looks like the windows is there, and only the
view is updated, I am using a widget to embed two scenes in TracksView, this
design is pretty much like USCSgenome browser, top scene shows a single
chromosome, never be zoomed, and bottom scene contains multiple tracks,
which zoom in/out at the same ratio.

To update this widget to visualize a new chromosome, I run the following
command without creating a new Qwidget
.....
 if(is.null(trackWidget)){
    trackWidget <<- Qt$QWidget()
  }
trackLayout <- Qt$QGridLayout()
trackWidget$setLayout(trackLayout)
......

This will give me a error saying the layout exists. it looks like it cannot
be simply over created.

I just solved the problem by keeping the layout with QWidget, so I simply
keep the top widget and layout at the same time, only create all scene and
view and layers, now it works, I am still wondering how to delete that
layout through, in case there is a use case in the future, such as update a
layout design of one specific GUI without destroying it.

Thanks

Tengfei
On Tue, Apr 12, 2011 at 12:15 AM, Michael Lawrence <
lawrence.michael at gene.com> wrote:

> The memory management is such that the memory will be deleted if there are
> no references to it from R or a Qt object. The "Qt object" part depends on
> the type of object being considered for deletion. In this case, a QLayout is
> a QObject, so it is owned by its parent. The parent is the widget (unless
> this is a sub-layout). So to delete the layout, you need to set NULL for the
> layout of the widget and rm() any references from R. And then run gc(). Let
> me know if that works.
>
> Changing the layout of a widget is a bit strange though -- what are you
> trying to do?
>
> On Mon, Apr 11, 2011 at 9:57 PM, Tengfei Yin <yintengfei at gmail.com> wrote:
>
>> Hi
>>
>> I hope to delete and create a new layout without destroying a widget,
>> based on Qt documentation,
>>
>> If there already is a layout manager installed on this widget, QWidget<http://doc.qt.nokia.com/4.7/qwidget.html> won't
>>> let you install another. You must first delete the existing layout manager
>>> (returned by layout <http://doc.qt.nokia.com/4.7/qwidget.html#layout>())
>>> before you can call setLayout() with the new layout.
>>
>>
>> to add a layout to an existing widgets,  I find something like
>>
>> void myWidget::makeLayout()
>> {
>>   // Delete old layout (if any)
>>   delete layout();  // This is QWidget::layout()
>>
>>   // Perhaps you have to remove, add, hide or show some childwidgets.
>>
>>  .....
>>   ...
>> }
>>
>> So how to do that in R, I cannot find something like close() or delete()
>> for QWidget$layout().
>>
>> Thanks
>>
>> Tengfei
>>
>>
>> --
>> Tengfei Yin
>> MCDB PhD student
>> 1620 Howe Hall, 2274,
>> Iowa State University
>> Ames, IA,50011-2274
>> Homepage: www.tengfei.name
>>
>>
>>
>> _______________________________________________
>> 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
>>
>>
>


-- 
Tengfei Yin
MCDB PhD student
1620 Howe Hall, 2274,
Iowa State University
Ames, IA,50011-2274
Homepage: www.tengfei.name
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/qtinterfaces-devel/attachments/20110412/91711d83/attachment-0001.htm>


More information about the Qtinterfaces-devel mailing list