A classical result of Euler states that the tangent numbers are an alternating sum of Eulerian numbers. A dual result of Roselle states that the secant numbers can be obtained by a signed enumeration of derangements. We show that both identities can be refined with the following statistics: the number of crossings in permutations and derangements, and the number of patterns 31-2 in alternating permutations. Using previous results of Corteel, Rubey, Prellberg, and the author, we derive closed formulas for both q-tangent and q-secant numbers. There are two different methods for obtaining these formulas: one with permutation tableaux and one with weighted Motzkin paths (Laguerre histories).