All items of one base type (eg Short Swords) have the same qlvl (Short Swords are qlvl 1 in fact). In a sense, qlvl measures "what the item is". The equipment TCs actually group together these qlvls in sets of 3 (eg TC3 is all qlvl 1, 2 and 3 equipment items). Even non-equipment items have qlvls though - anything that can spawn random mods (eg charms, jewels, rings) has to have one.
Each individual item has its own ilvl, which depends on its source and is obviously different from item to item. In a sense, ilvl measures "where an item comes from". Typically ilvl = mlvl of the monster/container that drops it, but cube recipes can also change it, and there are rules for shopped/gambled items too. (Shopped item: ilvl=clvl+5, but capped at ilvl 12, 20, 28, 36, 45 in the different acts in Normal; Gambled item: clvl-5?ilvl?clvl+4)
When the game tries to spawn random mods (this is on the creation of any new magic, rare or crafted item), it uses both the item's ilvl and the qlvl. It combines the two into another number called alvl, which indicates how high the mods are it can get.
The first step is to find the highest of ilvl and qlvl, as I mentioned above. Call that X.
Next, the game decides if the item is "high level" or "low level". This is basically a test to see whether X is more than 99 - (qlvl/2). Round down after the division, as always in D2. A qlvl 1 item is always "low level", and an item which is qlvl 66 or more is always "high level". In between, it depends on the ilvl.
If an item is "low level", then its alvl = X - (qlvl/2).
If an item is "high level", then its alvl = (2 * X) - 99.
This looks like a bunch of maths but isn't too hard to get your head around if you play with it a bit. A qlvl 1 item like a Short Sword, or more usefully, a GC or amulet, is always "low level" because ilvl is always at least 1 and less than 99. So for them, alvl = ilvl, and it is reasonably simple to work out which mods they can get.
For a qlvl 28 item like a SC, the first step means that any SC that is less than ilvl 28 can get the same mods as if it is ilvl 28, because in that case the qlvl takes over. SCs are considered low level up to 99 - (28/2) = 85, so for most of the time they are alvl = ilvl - 14. That means that for SCs,
if ilvl <= 28, alvl = 14
if 28 <= ilvl <= 85, alvl = ilvl - 14
if 85 <= ilvl, alvl = (2*ilvl) - 99.
So how do you decide if you can get a mod like Cruel? Well, Cruel on rares is alvl 56. For a high level item to get to alvl 56, it just needs to solve (2*X) - 99 > 56, which means X is at least 78, ie if either ilvl or qlvl are 78 or more, you're good.
But you could also get Cruel as a low level item. For that you need ilvl - (qlvl/2) > 56. In this case, unintuitively, it is better to have a low qlvl. A Short Sword can get Cruel at ilvl 56. However, a Long Sword (qlvl 20) needs to be ilvl 66, a Battle Sword (qlvl 40) needs to be ilvl 76, and by the time you get to Rune Sword (qlvl 44) you need to be a high level item anyway.
OK, unglaze your eyes, I'm almost done.
There is one group of items that are a big exception to this rule. They are "magic level" items, which are basically all circlet types, all staves and orbs, and all wands except for the elite ones (which is probably a bug). These guys each have a value called maglvl, and they skip the whole low/high level thing, and just have alvl = X + maglvl all the time. This lets them get better mods earlier than you would expect.
maglvl = 1 for all the weapon types that have it, but for the circlets, maglvls are
Circlet 3
Coronet 8
Tiara 13
Diadem 18
You may also observe that Diadems are qlvl 85, and so X is always at least 85, and so alvl for Diadems is always maxed out at 99 (tries to be 103 but it is capped). Diadems can always spawn all mods.