Hi,
I want to visibly group (and draw a rectangle around and fill the rectangle below of) some of my juce::TreeViewItems. I might be wrong, but it seems there is no juce::Component covering that area. How could I achieve this?
If there is already such a juce::Component how would I discover it?
Thanks!
I’d say either draw lines around the tree view items themselves using paintItem or create a whole separate floating component over the top and draw a box using the co-ordinates of the items found with getItemPosition.
Thanks @AdamVenn, for your suggestion!
Unfortunately paintItem() only draws the item itself, that is the area of the TreeViewItem itself, but not including the subitems. It’s juce::Graphicscontext clipping region only covers that area.
On the other hand a floating component would paint over the region, not allowing to fill the backgrounds of the TreeViewItem…
Do you want to draw a rectangle like this around multiple items?
What I meant with my second suggestion was that you could put a transparent, floating component as a child/sibling of the TreeView and move it around to align it with the items.
For my first suggestion, I mean that to draw the rectangle above you’d have to modify two TreeViewItems. In the top one, you would draw a line on the top, left and right. In the bottom one, the bottom, left and right.
Maybe I’m still misunderstanding the aim…
Thanks again, @AdamVenn, you were right. And the second solution works for me! I made my juce::TreeViewItemalso a juce::Componentand at the item creation I add the component to its parent, below the juce::TreeView.
This works but getItemPosition()doesn’t get negative when scrolling, so my item component stucks at the top when the tree view item moves out of it’s parent window…
Oh weird, do you just get zeroes? Maybe something with getViewport()?
no, I was wrong, getItemPosition() works, but drawing the rectangle in the graphics contexts does not work correctly, when the context is moved out. Then the origin remains in the visible area…
void paintItem(juce::Graphics& g, int width, int height) override{
auto bounds= this->getItemPosition(true);
bounds.removeFromRight(10);
this->setBounds(bounds);
TreeViewItem::paintItem(g, width, height);
}
void paint(juce::Graphics& g) override{
auto bounds= this->getBounds();
g.setColour(juce::Colour(0xff101020));
g.drawRoundedRectangle(20, 20, bounds.getWidth()-40, bounds.getHeight()-40, 40, 40);
}
I think I understand what happens here: The TreeView scroll only applies to the TreeView. The solution is to paint into the TreeView Component itself.

