Results 1 to 5 of 5

Thread: QCoreApplication vs QApplication has impact on QPainter ???????

  1. #1
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Unhappy QCoreApplication vs QApplication has impact on QPainter ???????

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCoreApplication vs QApplication has impact on QPainter ???????

    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.

  3. #3
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QCoreApplication vs QApplication has impact on QPainter ???????

    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...

  4. #4
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QCoreApplication vs QApplication has impact on QPainter ???????

    Qt Code:
    1. #include <QApplication>
    2. #include <QString>
    3. #include <QTextStream>
    4. #include <QRgb>
    5. #include <QImage>
    6. #include <QPainter>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication *app = 0;
    11. if(argc == 2)
    12. {
    13. // just add any parameter for gui mode
    14. printf("Running in GUI mode\n");
    15. app = new QApplication(argc, argv);
    16. }
    17. else
    18. {
    19. printf("Running in CONSOLE mode\n");
    20. app = new QCoreApplication(argc, argv);
    21. }
    22.  
    23. QTextStream out(stdout);
    24.  
    25. QImage image(128, 128, QImage::Format_ARGB32);
    26. QPainter painter(&image);
    27. QPaintDevice *device = painter.device();
    28.  
    29. out << "physicalDpi: x=" <<
    30. device->physicalDpiX()
    31. <<" y="<< device->physicalDpiY() << endl;
    32.  
    33. out << "logicalDpi: x=" <<
    34. device->logicalDpiX()
    35. <<" y="<< device->logicalDpiY() << endl;
    36.  
    37. return 0;
    38. }
    To copy to clipboard, switch view to plain text mode 

    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 ?
    Last edited by bmueller63; 2nd October 2010 at 09:13.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QCoreApplication vs QApplication has impact on QPainter ???????

    I have:
    Qt Code:
    1. chrisw@newton /tmp/test/m $ ./m
    2. Running in CONSOLE mode
    3. physicalDpi: x=75 y=75
    4. logicalDpi: x=75 y=75
    5. chrisw@newton /tmp/test/m $ ./m 1
    6. Running in GUI mode
    7. physicalDpi: x=93 y=95
    8. logicalDpi: x=93 y=95
    To copy to clipboard, switch view to plain text mode 
    on my Linux box. I used
    Qt Code:
    1. image.setDotsPerMeterX(3937);
    2. image.setDotsPerMeterY(3937);
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Determine if QCoreApplication or QApplication is running
    By doberkofler in forum Qt Programming
    Replies: 20
    Last Post: 17th September 2010, 19:45
  2. Replies: 0
    Last Post: 25th November 2009, 16:07
  3. Replies: 5
    Last Post: 7th September 2009, 21:57
  4. Replies: 3
    Last Post: 30th April 2006, 20:22
  5. <QtGui/QApplication> vs. <QApplication>
    By seneca in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 11:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.