[Developers] uiLabeledListBox 'trick'

Bert Bril Bert.Bril at opendtect.org
Mon Feb 25 12:43:37 CET 2008


Hi all,

This trick is not really a trick but I guess that ehh, because nobody
here got the idea before so we're either daft or it's just not as
obvious as it seems. Or ehhhh ...

Anyway, when you make a uiLabeledListBox, you're always working with the
box(). I used to store the pointer to the labeled list box, because
that's what you always do. The code looks like:

In .h file:
    uiLabeledListBox* listfld_;
In .cc:
    listfld_->box().addItem( "foo" );
    listfld_->box().addItem( "bar" );
    listfld_->box().setCurrentItem( 0 );

and so forth. Then I realized that I could just as well store the
pointer to the listbox only, as I never really used the label after
creation.

The only problem is in the very beginning: you cannot attach to the
listbox directly. This is because you cannot attach objects not
belonging to the same parent, and the uiLabeledListBox is a group
parenting the ListBox. Thus, the code becomes:

.h:
    uiListBox* listfld_;
.cc:
    uiLabeledListBox* llb = new uiLabeledListBox( this, "Types" );
    listfld_ = llb->box();
    llb->attach( alignedBelow, anotherfld_ );

    listfld_->addItem( "foo" );

etc.


Sure - it's only a cosmetic thing. But still.


Bert

-- 
-- Bert Bril / OpendTect developer at dGB
-- Nijverheidstraat 11-2, 7511 JM Enschede, The Netherlands
-- mailto:Bert.Bril at opendtect.org , http://opendtect.org
-- Tel: +31 534315155 , Fax: +31 534315104




More information about the Developers mailing list