If a printer has a custom paper size (for example 40x40) set as default page size, using QPrinter for that printer returns 'A4' (QPagedPaintDevice::A4) as a default page size.
Using a standard default page size, for example 'Letter' works just fine, so it seems like this bug is related to custom page sizes.
Setting the custom page size for the QPrinter works as expected, but default page size should not return 'A4' page size when a custom page size is set as default for the printer. It should return QPagedPaintDevice::Custom
This has been tested and reproduced with Qt 5.9.7 and Qt 5.12. This seems to work as expected in Qt 4.x
I have attached an example project to demonstrate this issue. In order to test it, you need to setup a custom printer driver which allows to use custom paper sizes.