Ex: I usually carry around 3 stacks of transport belts. In this example, I have 1 1/2 stacks (50+25) in my inventory and 1 stack (50) which is on a filtered toolbar slot. If I use 30 transport belts from my filtered slot in inventory, then press Q, the stack I'm holding (20) goes to my toolbar but the stack of 25 in my inventory doesn't get combined with it to make a new stack of 45. Instead, I have one stack of 25 in my inventory, and a stack of 20 in my toolbar.
Image, if that was too poorly worded. I just placed all the tracks except for 5 and hit q. I'm left with a stack of 50, a stack of 15, and a stack of 5 in the toolbar.

In general though, I think pressing Q to unselect a stack should cause an inventory sort as well. For example, if I pick up half a stack of solar panels from my main inventory, then press Q, the stack I'm holding goes to the toolbar (if free) but the other half stack stays in my inventory. Very odd behavior.
[edit]MATH
