The 25-year-old midfielder has agreed a four-year contract at Loftus Road after making 60 appearances for Los Blancos.
In a statement released by the Barclays Premier League club, R's boss Mark Hughes said: "He is a great player, first and foremost. You don't play at a club like Real Madrid if you're not."
Hughes added: "He has been there from the age of nine, so this has been a huge decision for him. He is very well regarded there and for him to leave a club of that stature to come to us shows the belief he has in what we are trying to do.
"He has got great energy and is technically very gifted, as you would expect from a Real Madrid player.
"He is very comfortable on the ball and is an all-round excellent midfielder, which we will benefit from."
QPR are also in talks with Marseille over Cameroon defensive midfielder Stephane M’Bia, although that move is dependent on Barton going the other way.
- Real Madrid
- Mark Hughes
- Barclays Premier League