Thanks @zeljan for answering my question in the comments.
Looks like this is a bug in the Lazarus 4.0 IDE with QT6 backend.
It'll be fixed in Lazarus 4.2 Stable: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41470
So if anyone has this issue in the future, just update your Lazarus IDE to the latest version.