Contextual letters

How can I create a contextual variation of a letter? For example I’d like to have a different Q for the combination of Qg or Qp or Qj.

You need to add a calt feature. Go to Font Info > Feature. Hit Plus > new Feature. Call it calt. then write in the textfield:
sub Q’ [g p j] by Q.alt;

Thank you! It works in Glyphs, but not in Indesign. Do I have to activate somewhere this feature?

Check if the feature is active in the OpenType menu.

Thanks a lot, it works perfectly.