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

Tengfei Yin yintengfei at gmail.com
Tue Apr 12 18:03:21 CEST 2011


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

>
>
> On Mon, Apr 11, 2011 at 10:54 PM, Tengfei Yin <yintengfei at gmail.com>wrote:
>
>> 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
>>
>>
> I just meant set the layout reference of the widget to NULL.
>
> trackWidget$setLayout(NULL)
>
>
>> 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 think you're saying that you're repopulating the layout. That makes more
> sense here. Another option would be to just switch the existing layers to
> look at a new chromosome. Why recreate everything?
>

This is open to discussion and not settle yet, current strategy is to
recalculate and process the data again if we switch to a new chromosome, if
we hope simply qudpate() a layer or scene to switch the chromosome, I have
to put the calculation into
the paintFun directly, this may cause a speed issue if this layer contains
other frequently changed drawing, like highlighted region.  Maybe another
way is to process everything (for all the chromosome) in advance for all
tracks so that the view and layer could be switched more quickly without any
computation, I am not sure if it's a good idea or not, the downside is that
you may store more information in the memory, unless we are thinking about
some advanced caching technique, maybe a data base or simply Rdata file? Any
suggestion?

"Recreate everything" sounds creepy, actually it only recalculate new
information(like SNP or overlapped bin) we need for new chromosome and
redraw the TracksView, it's a simple way though, since
obj$createView(seqname=NULL) method in the package does the job, I just
simply call this function and set it as the listener to some other event
which may switch the selected chromosome from other view(e.g StackedView)

Regards

Tengfei


 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
>>
>>
>>
>


-- 
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/572b911f/attachment-0001.htm>


More information about the Qtinterfaces-devel mailing list