My son is 4 and was chronically constipated. He started potty training at 2 but by 4 he still wasn't pooping on the potty. He was afraid that pooping would hurt his bottom and would hold it in until he just absolutely couldn't anymore. Then he would refuse to go unless we put a diaper on him. He would then roll around on the floor and whimper for 30-60 minutes before he was finally able to push the poop out. We would have multiple pairs of stained underpants daily when the poop was trying to come out but he was trying to hold it in. We had been to the emergency room once because he was so backed up. We had to go to the doctor once because he gave himself a prolapsed rectum from pushing too hard. I finally couldn't take it anymore - for my own sanity and because he just seemed so miserable. Right after his fourth birthday we finally went to a pediatric gastroenterologist and here's what we were told:
1. Give him Miralax daily to soften the poop. The most important thing is to make it as easy as possible for the poop to come out.
2. For the first couple of weeks if he didn't poop daily, give him a suppository.
3. Limit juice but no other dietary restrictions. Give him fiber supplements (I have been giving him Pedialax fiber gummies once daily) and push fiber rich foods whenever possible.
4. When he sits on the potty, help him get on then go about my business. Don't make it a big ordeal. Check on him and help him wipe. If I stop everything I'm doing whenever he poops, he has control and he knows that's how he can get my attention.
It took about a week of giving him the right dose of Miralax for everything to soften up enough for him to go regularly. I decided to not do the suppository the first week in order to give the Miralax a chance to work and because it was going to be unpleasant for both of us and I feared that trauma would further hurt my cause. When things finally started working, he refused at first to go on the potty. After 5 (FIVE!) full diapers worth of poop (think blowouts, 4 year old style - gross!) I finally convinced him to sit on the potty. This worked because he was aware that he had pooped several times without trying very hard and it didn't hurt him.
Since then he has been completely successful going on the potty and we rarely have stained underwear.
Our specialist did say that about 5-6 percent of kids are chronically constipated. And, for those who are, they need assistance (stool softener) for years before their bodies get going on their own. However, no other special medical attention is needed as long as the stool softener is doing it's thing.
I would suggest working with your pediatrician if this continues. It's a combination of physical issues and behavioral issues (trying to control her bowels and you).
Good luck! I know how hard this is.