In doPaint and doRepaint methods of WidgetContainer, check if the widget being painted is visible.