What I am trying to do is create a bar graph that can be resized by the user. I have a long narrow horizontal widget for the graph and a variable number of child widgets that each go into it. The child widgets each have a length that is a fraction of the total length. If I make the graph a fixed width it works fine. To make it stretchable I rewrote the resizeEvent() function but it doesn't quite work correctly. From what I can tell the widget is created short and then lengthened to fit the layout it goes into. The first time the graph is shown its segments are all the wrong size. As soon as it gets redrawn or resized they all snap to the correct size. I have tried explicitly calling update() updateGeometry() and repaint() but nothing has worked. BTW I am using child widgets rather than painting the main widget so I can connect a custom context menu to each one.
Any help or insight would be appreciated, thank you.
In the following code widgets[x] is a QList<QWidget *> of the widgets that make up segments of the bar graph. SizeChart is the parent widget.
void SizeChart::resizeEvent(QResizeEvent *event)
{
int new_width = (event->size()).width();
for(int x = 0; x < widgets.size(); x++){
widgets[x]->setMinimumWidth((int)(new_width * fractions[x]));
widgets[x]->repaint();
widgets[x]->update();
widgets[x]->updateGeometry();
}
repaint();
update();
updateGeometry();
}