I am producing a toc, but not in the Scribus sense, with annotations. I go through all pages, through all textframes, get the text with getText, that returns only the text of this textframe. This works also for linked frames, as opposed to getAllText, that returns on each linked textframe the concatenated text of all textframes before and after this frame. Now I can search in the text of this page for something I like to appear in the toc, and I know the page number too.
But then I have a special case: I do not want some piece of text, like a header1, to appear in the toc, but some text I derive from the dataset that produced the text. Therefore I "hide" an id of the dataset with 1 point font, no colour, in the text, and have a special button, that deletes the ids when the toc is finished. Before the ids are removed, you can only see that there is some little space where the id is hidden, but with a zero width font this little space would go away completely.
From the id I retrieve the dataset, produce some text from the dataset, and put it together with the page number into a new textframe, that then becomes the toc.
I still wonder why Scribus stops at 1 point and 10% horizontal scaling.
Btw: I just watched a tutorial from Affinity Publisher. There, they use styles for the toc. Each text with a selectable style, e.g. header1 or header2, is put into the toc.