How to detect if query is runned from widget?

You could use the is_main_query Function :

http://codex.wordpress.org/Function_Reference/is_main_query

Happy Coding, Kuchenundkakao