This has so far only worked in creative mode for me.
1. grab any item or block
2. open the inventory
3. pick your item/block and drop it outside of the inventory (won't work by pressing Q outside of inventory)
4. it will be picked up and placed in the inventory
5. drop it again
6. you will now have 2x items/blocks
7. repeat step 5.
If you already have more than one item this will also happen:
1. right click the items and drop it like previously.
2. it will stack with the others
3. right click again and drop
4. it will duplicate and stack
full video: https://www.youtube.com/watch?v=tkOi96yU6Xs