You can, but it would help if you added a UI element to have the user let your app know that they changed media. The printer has no way of really knowing that the media type changed and assumes the user always is using the same media. The QLn is 8 dots per mm.
So you flow is:
handle media change event
send: '~JC' to tell the printer to auto-detect label length
add the ^PW command to your label formats to set the width dynamically or just send it separately as '^XA^PW400^XZ'
You can also send the ^SS command to set the label length programatically, but it is not recommended as this can result in extra blank labels being printed occasionally and shorter printhead life as it is more likely to try to print on the web surface.