Q formats are simply scalings from integers to fractional values.
Let’s consider the bits in byte, numbered from 0 (on the right when the bits are written out) to 7 (on the left). In the common binary notation, bit i represents a value of 2i. The value represented by the eight bits is the sum of the values represented by the set bits, so 01000011 represents 67 (26 + 21 + 20).
When two’s complement is used to support negative numbers, the highest bit, bit 7 in this example, represents the negative of its plain binary value, so −27.
In a “Q” format, the values of these bits are shifted. In a Q7 format, bit i represents 2i−7, except value for the highest bit is negated, so bit 7 is −27−7 = −1. The name may also be written Q0.7. Conceptually, these numbers are tell us where we put a “binary point” (like a decimal point) in the bits to read the value represented. A Q3.4 format has a sign bit, three bits before the binary point, and four bits after the binary point, like 0100.0011, and it represents 4 + 3/16 = 26−4 + 21−4 + 20−4 = 22 + 2−3 + 2−4 = 4 + 1/8 + 1/16 = 4 3/16.
Another way to think of this is that the bits that represent some x in a plain binary (or two’s complement) format represent x/2n in a Qm.n format.
If your compiler had a fully supported q7 type, you could just assign values to it without dealing with how they are represented: q7 x = .25; would initialize x to contain the value 1/4 by putting the bits 00100000 into it.
From your example, it seems you may have a “do it yourself“ Q7 type that is really just an eight-bit signed integer. In that case, you have to do some conversion between the represented values and the Q7 type. Given any eight bits that represent the integer x, they would represent x/128 in the Q7 format, because in the Q7 format, the bit with value 2i in the integer format has value 2i−7 in the Q7 format.
Thus, if you have some float f, and you want to store it in the Q7 format, using q7_t x = f * 128; adjusts f to the corresponding value in the normal scaling for integers. Conversely, x / 128.f takes the integer value represented by x and scales it to what the bits represent in the Q7 format.