PDA

View Full Version : QCoreApplication vs QApplication has impact on QPainter ???????



bmueller63
1st October 2010, 23:05
Hello,

I am new to the forum - but no newbie to Qt (I use it since version 2.x)...

I have a very strange behavour in an application I am currently developing. I use Qt4.7 on MacOS Snow Leopard.

I built an App which simply adds several sprites to one bigger image (drawing the images using QPainter) and stores the image. It additionally stores a list of coordinates.

When I use QCoreApplication everything works fine.

If I use QApplication the data file with the coordinates is exactly the same. But the image file is not!
The output image size is the same but the complete contents (images + position of them) is scaled down by about 10%.

I firtst thought about uninitialised variables but the compiler did not complain about that. The behaviour is completely reproducable. I use unit tests to test the files I create - every file shows the same problem!

Has anybody an idea?

Thanks
bm

ChrisW67
2nd October 2010, 07:07
Sounds like you have a transform in place on the painter. Without seeing a small, compilable example that reproduces the behaviour I doubt anyone is going to be able to help. If all you are doing is changing the application object then there's no reason to expect a changed output.

bmueller63
2nd October 2010, 07:38
I think I found the problem:

The images are not really different. Araxis Merge shows the size difference. In Photoshop both images are exactly the same.

The difference is that if I use QCoreApplication the image's dpi value is 75 but when I use QApplication it is set to 72.

Araxis does a scaled compare this is where the difference comes from...

But: I still think that Qt should not set other DPI values when using a QCoreApplication vs QApplication.

Currently I am searching for a way to change the output's dpi value...

bmueller63
2nd October 2010, 08:03
#include <QApplication>
#include <QString>
#include <QTextStream>
#include <QRgb>
#include <QImage>
#include <QPainter>

int main(int argc, char *argv[])
{
QCoreApplication *app = 0;
if(argc == 2)
{
// just add any parameter for gui mode
printf("Running in GUI mode\n");
app = new QApplication(argc, argv);
}
else
{
printf("Running in CONSOLE mode\n");
app = new QCoreApplication(argc, argv);
}

QTextStream out(stdout);

QImage image(128, 128, QImage::Format_ARGB32);
QPainter painter(&image);
QPaintDevice *device = painter.device();

out << "physicalDpi: x=" <<
device->physicalDpiX()
<<" y="<< device->physicalDpiY() << endl;

out << "logicalDpi: x=" <<
device->logicalDpiX()
<<" y="<< device->logicalDpiY() << endl;

return 0;
}

Here's the result on my Mac:


$ BugTest
Running in CONSOLE mode
physicalDpi: x=75 y=75
logicalDpi: x=75 y=75

$ BugTest gui
Running in GUI mode
physicalDpi: x=72 y=72
logicalDpi: x=72 y=72


I would accept this change if I paint on the screen - but its painted in a background buffer.....

I am currently a bit unsure on how to proceed now...
Create a new QPaintDevice and override
virtual int metric ( PaintDeviceMetric metric ) const ?

Or use QImage setDotsPerMeterX/Y ?

ChrisW67
2nd October 2010, 22:41
I have:

chrisw@newton /tmp/test/m $ ./m
Running in CONSOLE mode
physicalDpi: x=75 y=75
logicalDpi: x=75 y=75
chrisw@newton /tmp/test/m $ ./m 1
Running in GUI mode
physicalDpi: x=93 y=95
logicalDpi: x=93 y=95
on my Linux box. I used
image.setDotsPerMeterX(3937);
image.setDotsPerMeterY(3937);

to set 100DPI and the resulting saved images had the same DPI figures installed (and hence the same 'print size'). The distinction is only really relevant if you are going to put the image pixel-for-pixel onto a device with a different DPI and expect the same physical dimensions on the image.