Picamera2 live preview not working

So I am trying to pyQT and then picamera2 API to develop a GUI to control the HQ camera. I am following the documentation and confirmed the basic test works and the camera does take an image with a preview shown for “x” seconds.

from picamera2 import Picamera2, Preview
import time
picam2 = Picamera2()
camera_config = picam2.create_preview_configuration()
picam2.configure(camera_config)
picam2.start_preview(Preview.QTGL)
picam2.start()
time.sleep(2)
picam2.capture_file("test.jpg")

However when I try to run the example preview code it just shows a black screen on the preview for half a second and then juts quits out.

from picamera2 import Picamera2, Preview
from libcamera import Transform
picam2 = Picamera2()
picam2.start_preview(Preview.QTGL, x=100, y=200, width=800, height=600,
transform=Transform(hflip=1))
picam2.start()

How do I make it show a preview indefinitely and not have the black screen it shows? Thank you

What guide are you following?
What OS are you running?
Have you seen this?
Camera software - Raspberry Pi Documentation

I am running raspberry pi OS bookworm 64bit using the picamera2 api. GitHub - raspberrypi/picamera2: New libcamera based python library

From what i understand rpicam is from terminal only? Does it have a python api.

Ok, I think I may have jumped the gun, and misunderstood what you were trying to do? Hopefully somebody more knowledgeable to help you out? Sorry about that.