A tunable and narrow-bandwidth Q-switched ytterbium-doped fiber (YDF) laser is investigated in this paper. The non-pumped YDF acts as a saturable absorber and, together with a Sagnac loop mirror, provides a dynamic spectral-filtering grating to achieve a narrow-linewidth Q-switched output. By adjusting an etalon-based tunable fiber filter, a tunable wavelength from 1027 nm to 1033 nm is obtained. When the pump power is 1.75 W, the Q-switched laser pulses with a pulse energy of 10.45 nJ, and a repetition frequency of 11.98 kHz and spectral linewidth of 112 MHz are obtained. This work paves the way for the generation narrow-linewidth Q-switched lasers with tunable wavelengths in conventional ytterbium, erbium, and thulium fiber bands to address critical applications such as coherent detection, biomedicine, and nonlinear frequency conversion.