We investigate quantum Otto engine and refrigeration cycles of a time-dependent harmonic oscillator operating under the conditions of maximum Q function, a trade-off objective function which represents a compromise between energy benefits and losses for a specific job, for both adiabatic and nonadiabatic (sudden) frequency modulations. We derive analytical expressions for the efficiency and coefficient of performance of the Otto cycle. For the case of adiabatic driving, we point out that in the low-temperature regime, the harmonic Otto engine (refrigerator) can be mapped to Feynman's ratchet and pawl model which is a steady-state classical heat engine. For the sudden switch of frequencies, we obtain loop-like behavior of the efficiency-work curve, which is characteristic of irreversible heat engines. Finally, we discuss the behavior of cooling power at maximum Q function.