The director Francois Ozon has chilled since early bad boy movies like “Criminal Lovers” and “Swimming Pool.” But he still likes to push buttons. The worst you can say about his latest, the transvestite comedy “The New Girlfriend,” is that he’s simply trying all he can to get a rise. The best you could say is he’s made a mildly incoherent mess that revels in its reckless upchucking of ideas. Like “Potiche” and “In the House,” it’s a bright and chipper comedy with a heavy subversive streak, intended to lure in middlebrow audiences while making them squirm. It’s “La Cage Aux Folles” with several heavy heapings of psychosexual tension, plus one strong, devastating idea that it never develops — that becomes just one of many great notions it keeps throwing at you.

Typical of the film’s — and Ozon’s — grim sense of humor is the way it opens. Close-ups of a woman, Laura (Islid de Besco), getting done up in a dress and make-up lead us to believe she’s getting married. Instead she’s being buried. Laura has died, leaving not only a husband, David (Romain Duris), and a baby but also Claire (Anais Demoustier), her best friend since childhood, with whom she shared an intense love that was never consummated. Claire accidentally discovers David has a secret: He likes to dress up in Claire’s clothes, adopt overtly, old-timey feminine body language and call himself Virginia. It’s partly out of grief but mostly because he’s always liked to play dress-up and tap into a key but otherwise ignored part of his personality. Soon they're both out and about, even nabbing a semi-sarcastic shopping montage set to Katy Perry.

There’s a devastating, usefully messed-up, “Vertigo”-esque film in here that finds Claire’s long sublimated desires for her departed bestie getting a kind of second chance with David/Virginia, just as David is channeling his late wife by donning her clothes. This is mostly ignored, but it periodically comes back, in ways that are both frustrating for the viewer but also moving. After all, Claire is someone who has long bottled up her longings and is wary, still, in 2015, of letting them surface. Claire’s the one who calls David a “pervert” and a “tranny,” but this is clearly a defense mechanism. Or perhaps she’s just a sketchily, underwritten character. Either way, Demoustier’s touching performance irons out the considerable kinks in a character that occasionally seems contradictory — sometimes on purpose, sometimes because of sloppy writing.

Some have accused Ozon’s portrayal of transvestitism as offensive, though there are filmmakers more worth charging as reactionary than Ozon, whose body of work is filled with not just LGBT issues but ideas of gender and sexual fluidity. David/Virginia is played for laughs but in a warm, welcoming way, not one that encourages regressive thinking. Ozon, adapting a novel by Ruth Rendell, loves to play with the specifics of David’s sexuality. At one point, dressed to the nines, he’s groped in a movie theater. He clearly enjoys it but then states he’s not actually into men sexually; he just likes that he was able to pass himself off as another gender.

“The New Girlfriend” loves going to weird, perhaps shocking places, in part to point out that they shouldn’t seem weird or shocking. The second half throws out so many ideas, some mere dream sequences or fantasies, that the whole thing seems even more rickety than Duris’ game attempt at playing an old-fashioned female — itself meant to note the way modern women, by and large, no longer subscribe to broad, bygone definitions of femininity. “The New Girlfriend” starts a lot of conversations, one of them being whether Ozon has ever, in any of his films, been able to focus his imagination into something coherent rather than scattershot.