Tried with OpenCV 4.6 and 4.8. Should work for most versions.
# in a new folder Downloads/opencv
# core dependencies / tools
sudo apt update && sudo apt install -y cmake g++ wget unzip
# GTK packages - because building with QT does not work (at least with OpenCV 4.6)