Results 1 to 6 of 6

Thread: QPicture does not play right

  1. #1
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QPicture does not play right

    Hi,

    I have the following code:
    Qt Code:
    1. void xpPageWidget::setPage(QPicture* image)
    2. {
    3. m_Pixmap.fill(Qt::white);
    4.  
    5. QPainter painter(&m_Pixmap);
    6.  
    7. qDebug(ds_filepos+QString("MPageDisplay::setPage(): image =%1x%2").arg(image->width()).arg(image->height()));
    8. qDebug(ds_filepos+QString("MPageDisplay::setPage(): m_Pixmap=%1x%2").arg(m_Pixmap.width()).arg(m_Pixmap.height()));
    9. qDebug(ds_filepos+QString("MPageDisplay::setPage(): this =%1x%2").arg(width()).arg(height()));
    10.  
    11. image->play(&painter);
    12. //painter.drawPicture(0,0,*image);
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 

    And the output:
    Qt Code:
    1. .\gui\xpPageWidget.cpp(29): MPageDisplay::setPage(): image =732x327
    2. .\gui\xpPageWidget.cpp(30): MPageDisplay::setPage(): m_Pixmap=794x1123
    3. .\gui\xpPageWidget.cpp(31): MPageDisplay::setPage(): this =796x1125
    To copy to clipboard, switch view to plain text mode 

    image get's painted to by code like this:
    Qt Code:
    1. void ReportBase::drawFrame(QPainter *p,QRectF aRect)
    2. {
    3. if(!p) return;
    4. QPen aPen = m_BorderColor;
    5. ...
    6. p->setPen(aPen);
    7. p->drawLine(aRect.topLeft(),aRect.topRight());
    8. ...
    9. }
    10. bool ReportBase::draw(QPainter *p)
    11. {
    12. drawFrame(p);
    13. if(m_ReportEngine->m_ShowNames)
    14. {
    15. p->setPen(Qt::lightGray);
    16. p->setFont(getFont());
    17. p->drawText(*m_Rect,Qt::AlignCenter,QString("%1:%2").arg(className()).arg(name()));
    18. }
    19. return true;
    20. }
    To copy to clipboard, switch view to plain text mode 

    The painting worked fine in Qt3 (1st Block line 11: image->play(&painter) ) but in Qt4 the QPicture painting is too big and goes off my pageWidget. The only way to get it within the required 796x1125 (A4 Paper) area on pageWidget (see output) is to scale it ... I still have to work out the correct ratios for QPainter::scale ( qreal sx, qreal sy ) to make it fit snuggly but that seems like something that should work without scaling.

    Thus, is there some scaling/transformations when the paint commands are played back to a QPainter? What's the pixel size of an A4 Paper... would that be a potential issue?
    Derick Schoonbee

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPicture does not play right

    Quote Originally Posted by derick
    What's the pixel size of an A4 Paper... would that be a potential issue?
    It is an issue. Paper does not have pixels, but every device (like monitors or printers) has different pixel size depending on current resolution (and hardware). You can obtain the all the information you need using QPaintDevice class.

  3. #3
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPicture does not play right

    I've calculated that the with it draws 'too wide' on is 200pixels.

    Then my output is:
    .\gui\MPagedisplay.cpp(29): MPageDisplay::setPage(): image =532x327
    .\gui\MPagedisplay.cpp(30): MPageDisplay::setPage(): m_Pixmap=794x1123
    .\gui\MPagedisplay.cpp(31): MPageDisplay::setPage(): this =796x1125

    And it draws correctly on the page.

    I would expect a 794x1123 QPicture to play back properly on a 796x1125 QPixmap using a QPainter
    Derick Schoonbee

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPicture does not play right

    Quote Originally Posted by derick
    I would expect a 794x1123 QPicture to play back properly on a 796x1125 QPixmap using a QPainter
    int QPaintDevice::width () const
    Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).
    See also widthMM().
    This means QPicture::width() and QPixmap::width() might return size in different units (pixels from QPicture and from QPixmap might have different sizes). Try widthMM() method.

    QPicture always runs in 72 dpi, and scales the painter to match differences in resolution depending on the window system.

  5. #5
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPicture does not play right

    Thanks for the tip. The display dpi was higher.. thus here is the fixed code:
    Qt Code:
    1. void MPageDisplay::setPage(QPicture* image)
    2. {
    3. //A white page
    4. m_Pixmap.fill(Qt::white);
    5. // Convert from painting/printing resoltion to on screen
    6. qreal sx = (qreal)image->logicalDpiX()/(qreal)m_Pixmap.logicalDpiX();
    7. qreal sy = (qreal)image->logicalDpiY()/(qreal)m_Pixmap.logicalDpiY();
    8.  
    9. QPainter painter(&m_Pixmap);
    10. painter.scale(sx,sy);
    11. image->play(&painter);
    12. }
    To copy to clipboard, switch view to plain text mode 
    Derick Schoonbee

  6. #6
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPicture does not play right

    Sniff Sniff ... because QPicture can only record paint events at 72dpi and printers go from 300 - 600dpi my printouts are not good.

    I scaled the image on painting but it comes out a bit fuzzy...

    Does anybody have some ideas on how to cache paints ... QPixmap seems like a waste of memory since I would like to view the pages onscreen.

    Painting an oversized image to get the quality better perhaps?
    Derick Schoonbee

Similar Threads

  1. how to play media files.
    By hrudhay in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th August 2008, 11:24
  2. Phonon Media Object blocking on play()
    By traetox in forum Qt Programming
    Replies: 0
    Last Post: 21st May 2008, 06:43
  3. Drawing speed: QPixmap vs QPicture
    By maverick_pol in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 20:17
  4. Play gif file in QTextEdit field
    By vishesh in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 16:28
  5. QPicture Clip
    By whitefurrows in forum Qt Programming
    Replies: 5
    Last Post: 23rd July 2006, 14:41

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.