"If only..." is a poetic-sounding phrase that's used to express something you wish had happened. It brings to mind an image of someone imagining how much better life would be if this imaginary event had happened.
Because of its poetic tone, "if only" is not used when someone is really angry about how things happened. It's used in situations where you wish things had been different, but you accept that you can't change the past.
This can be used to express what actions should have been differently, like in the example at top, or what conditions should have different:
If only it hadn't rained, we could have cooked out on the grill.
You can use this phrase by itself, without telling what the result would be:
If only I'd listened to her...