The example that puzzles you is allocation on the stack. The bracketed part of the expression is the arguments to the QPainter constructor. If you wrote:
you would be creating a QPainter using its default (parameterless) constructor. The example you give uses a different constructor to build the QPainter and initialise it in some way. The constructor options are in the Assistant docs for QPainter. The same syntax can be used to initialise ('construct') basic types created on the stack:
You have given a (slightly incorrect) example of allocating the QPainter on the heap.
Your second example may be either stack or heap (with the same missing * as your first) depending on what your fictious QPainter::fromWidget() is supposed to return (a pointer or an instance of QPainter).
Bookmarks