BListView question

Hi All,
BListview can support different row height for BlistItem ?

Each BListItem can have its own height. See the documentation at https://www.haiku-os.org/docs/api/classBListItem.html#a637ad01974e7a9c44439fb88f2052f67 in particular the SetHeight() function. Though it’s usually best is you set the height before you display the item. If you change it when it is already being displayed, it won’t update automatically (the docs have a workaround).

1 Like

Thanks for this information,

Try below but doesn’t work
don’t see where my mistake

class CityItem : public BListItem
{
public:
CityItem(const char *city, int32 region = 0);

virtual void Update(BView *owner,BFont *ft);


  virtual void DrawItem(BView *owner,
        BRect frame,
        bool complete = false);
  enum { USA, ASIA, EUROPE, AUSTRALIA, OTHER };

private:
BString kCity;
int32 kRegion;
};

const char *region_names[] = {
“USA”, “Asia”, “Eur.”, “Aust.”, “Other”
};

CityItem::CityItem(const char *city, int32 region)
: BListItem()
{
kCity = city;
kRegion = region;

}

void CityItem::Update(BView *owner,BFont *ft)
{
BListItem:Update(owner,ft);
}

void CityItem::DrawItem(BView *owner, BRect frame,
bool complete)
{
BView *vx = owner;

rgb_color r = {0};

r.red = 255;

vx->SetHighColor(r);

vx->FillRect(frame);

}

class myLb : public BListView
{
public:

					myLb(BRect r);

};

myLb::myLb(BRect rc):BListView(rc,"",B_SINGLE_SELECTION_LIST,B_WILL_DRAW)
{
}

// code on the window

myLb *l0 = new myLb(BRect(10,10,400 ,400));

s0 = new BScrollView("",l0,B_FOLLOW_LEFT,0,false, true,B_FANCY_BORDER);

vx->AddChild(s0);

CityItem *cc = new CityItem("Chicago", CityItem::USA);

cc->SetHeight(100);

l0->AddItem(cc);

l0->FrameResized(l0->Bounds().Width(),l0->Bounds().Height());

l0->Invalidate();

Can you post the code on Pastebin? It is a lot easier to read that way.

Some questions … since i cant see andy obvios “error”.
Is there a error message while compiling?
If not… what is the outcome (what is different from what you expected)?
What kind of View / window is vx?
Does vx use the Layoutmanager?

Hi All,
Thanks for your help, sorry the missing information
I put on DropBox a little project
Project download link (created with Paladin)
He display a simple ListView with a unique row (filled with red color)
I want set the row height to 100pixels but it’s the problem :wink:

Since i dont have Haiku here running… i cant answer it perfektly…

but i think, since you first set the height and then you add it to the List i guess
Update (of the listitem) will be called and sets the height back to the font height…

So i guess two solutions are possible:

  1. try to add you Listitem afert everything has been added to the window (Srcollview, ListView)
  2. (better one) implement your own update or height MEthod
    e.g. https://github.com/Paradoxianer/FontPanel/blob/48e0149769a29b35913a5af2554ea6e4972399ca/FontListView.cpp#L202
1 Like

Thanks Paradoxon,
Work well with your example code!

1 Like