I wrote this script regarding this post:
https://qcad.org/rsforum/viewtopic.php?t=9355
And it is already very helpful.

The tool will activate the layer that the entities in selection have in common.
Therefor it requires a selection upfront.
It will report an ambiguous selection disregarding the actual current layer being ambiguous with others in the selection.
It does not re-activate a current active layer but will report that the selection is on the current layer.
Setting a layer active is a two step process, it requires an extra action to fully undo.
With 'Y' there are not many options left for the shortcut (b, g, j, q, x).
### Update see lower ###
Opted for the key sequence 'YJ' what doesn't seem to conflict.
### Updated to 'YG' ### (Because of conflict in later QCAD versions)
Had some hiccups in coding it ...

For one, creating subfolders including the hierarchy separator ' ... ' acts weird.
For PRO users it will now also expand the layer tree so that the active layer is at least visible.
The reasons for that are:
- On reloading a drawing all main level parents are collapsed.
Sublayers only may retain their expanded/collapsed state.
- A drawing may open without the current active sublayer visible.
- Expanding/collapsing a level in the Layer List is also setting it active.
The tool should work for CE users just the same. Can anyone confirm that?
### Updated, now CE proof ### (Tested in v3.32.3 as CE)
Initially intended as a tool in the Layer menu but reverted back to the Misc .. Layer menu.
Details are in the init script and scripts are textual files.
Scrolling the Layer List would be a nice addition


### Implemented ### (CE and Pro)
The 5 files in the zipper can be installed in your QCAD installation path under ...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\
Where the 3 dots stand for your QCAD installation folder (CE, Pro, QCAD/CAM or appropiate)
Or in the local data location, see Changelog ... 3.26.2 (2021/04/15):
https://www.ribbonsoft.com/en/documentation/changelog
Please also refer to this answer by Andrew to detect your specific user data location.
- Folders:
...\scripts\Misc\
...\scripts\Misc\MiscLayer\
...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\
May not exist in a standard installation, create them manually.
...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\ActivateLayerFromSelection.js
### UPDATED ###
The addon was downloaded 510 times before the revision.
Andrew may include this in a future release of QCAD.
In such a case one would delete these installed files and additional the emptied folders.
Andrew may also decide to implement it as a Layer tool, details are in the initialization file.
In such a case one must remove those that are installed in the Misc menu to avoid conflicts.
Regards,
CVH