At first sight you seem to be generating output inside a PHP class file:
That should be avoided (always).
If you want to add HTML when you output a widget then you should use the $themeobject parameter or pass by reference the &$qa_content parameter. The problem is that widgets are output AFTER the theme has processed the theme head() function. That means if you edit the content in the widget the content array will be updated but that HTML won't be output.
There isn't much to do here unless the widget loading receives a kind of initialization($qa_content) function that would run before the output_widget function, just after the theme initialization. However, the core doesn't have that (and most likely it should).
So widgets can't solve the issue on their own. They need a layer. As layers literally extend the theme they can hook (override) any method and edit the content array. I usually prefer the latter. This means you could just add an initialize() function to the layer and change $this->content['css_src']) and $this->content['script'] accordingly. Instead of 'script' you can also use 'body_footer' for the JS.
The problem now is that the new HTML is output all the time. You can add some conditions to try to avoid this by processing $this->content['widgets'] in the layer but might complicate things too much. Probably, it is better (easier) to output the CSS all the time and, in the case of the JS, add it to the footer so that you can add it in the output_widget function directly.