@VRonin you probably need a software copyright layer to answer that :)
My totally layman understanding (and now I take my work hat off, as this is code owned by my employer) is that in Finland (and probably most of the EU) you would be safe if the code you are copying is practically the only way to do it, and it is so simple that it is the only reasonable solution to your problem, and that the part you are copying is short enough that could simply re-write it anytime, and you aren't copy pasting anything else from the same work.
The problem is that everything I'm saying above is way too hand-wavy to be of any use. It's always a case-by-case situation.
Linking has nothing to do with it. It is a question of does the copy-pasted material automatically bring it's license with it to your code.
If you wanted to be utterly safe, you would ask your friend, who has not seen the Qt code to implement a paintEvent once, and then use that. He probably would come up with about the same seven to ten lines of code. (clean room is the only way to be totally sure)