There’s a funny scene in the Star Trek: The Next Generation episode “Tapestry” where Captain Picard wakes up in bed next to Q.
The characters have the following dialog (copied from here):
Good morning, darling.
Picard jerks back in shock. Q smiles as Picard grabs
his uniform and begins to dress.
A little jumpy this morning, are
we? Feeling guilty perhaps?
I don't have anything to feel
guilty about, Q.
"We were friends, Q. Nothing
You're the one who gave me the
opportunity to change things...
So what happens next?
Picard thinks for a beat.
I don't know. But I do know that
things will be different.
Q looks at him for a beat.
What’s important to understand here is the context of the scene. It’s implied that Picard just had sex with Marta, a female friend he’d fallen out of touch with years ago.
Or did they really have sex? It’s not clear any of what’s happening here is entirely real.
The backstory is that Picard died, and while on the operating table he wakes up in an all-white room. Who should be standing there but Q, an annoying man who has god-like powers but spends his time tormenting people.
Q gives Picard a choice: stay here and you’ll probably die, or I’ll take you back in time so that you can change the past to avoid death.
Picard’s choice is obvious, despite the fact that he doesn’t believe anything Q has to say; after finding Q standing over him in the afterlife, Picard quips that Q can’t be here because “The universe is not that badly designed.”
In spite of his initial misgivings Picard relives his past and makes new choices to allegedly prevent his death. One of those choices is having a relationship with Marta.
But is Picard’s initial instinct correct? Is Q messing with him?
A.V. Club’s Zack Handlen points out three ways to interpret Q’s offer:
 Q insists to Picard that what we’re seeing is the actual past, instead of a construct [...]
 [T]he easiest being that nothing that happens here is really “real” at all, that all of it is created by Q to teach Picard to accept that the man he was is responsible for the man he is,
 or else it’s just Picard having a death-bed hallucination.
Handlen finds the second option most likely. While the setup is reminiscent of the Dickens classic “A Christmas Carol,” throwing Q into the mix complicates the scenario. I agree with Handlen’s reasoning — rather than pure Dickens-style fantasy, this seems to be all Q’s doing. It’s entirely in character for Q to mess with Picard’s mind by creating meaningless choices like this, and the episode seems to bear this theory out.
So if Picard had a sexual encounter in Q’s recreation of the past then who did Picard have sex with? Marta couldn’t have been there, so did he have sex with some kind of recreation of her? Or did Picard essentially have sex with Q?
Now look, I’m not saying Picard is gay. And as far as I can tell Q is asexual (though he gets off on tormenting people.) But that doesn’t mean Q can’t summon sex partners from his own mind. Presumably Q would have to animate the people he creates in some way. In the context of Q replacing his facsimile of Marta with himself when Picard woke up, Q’s dialog (as above) seems intentionally flirtatious. The question is then of whether Q was the one behind Marta’s mask or whether it was Picard’s vision of her that brought her to life.
If we go with the theory that Picard fell into Q’s trap, then what does that say about Q’s actions? Did Q rape Picard physically (rather than mentally) this time? Or by finally buying into Q’s world, did Picard effectively submit to Q’s advances?
As with any fiction the story’s questions are ultimately up to the audience. A show like TNG gives the audience plenty of questions, but few seem so directly targeted at those writing slash fiction.