Results 1 to 17 of 17

Thread: Printing a QGLWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Printing a QGLWidget

    I am trying to print a QGLWidget to a printer. When I do print, I only get the background of my QGLWidget with its grid lines. My QGLWidget is a plot with titles, axis labels, and tick marks as well as data and grid lines. You can see when the grid lines print where the data should be because the grid lines are missing in small spots where the data lies on top of the grid lines. mpPrinter is created in my constructor and mpCentralFrame holds a QHBoxLayout which only holds my QGLWidget. Instead of grabbing the window of the frame I have also tried just grabbing the QGLWidget and have received the exact same results. I have set up my print function to look like this:

    Qt Code:
    1. void myClass::print( )
    2. {
    3. if( mpPrinter == NULL )
    4. {
    5. fprintf( stderr, "No printer available\n" );
    6. }
    7. QPixmap imageToPrint = QPixmap::grabWindow( mpCentralFrame->winId( ) );
    8. QPainter painter( mpPrinter );
    9. QRect rect = painter.viewport( );
    10. QSize size = imageToPrint.size( );
    11.  
    12. mpPrinter->setPrintProgram( QString( "lp" ) );
    13. mpPrinter->setColorMode( QPrinter::Color );
    14. size.scale( rect.size( ), Qt::KeepAspectRatio );
    15. painter.setViewport( rect.x( ), rect.y( ), size.width( ), size.height( ) );
    16. painter.setWindow( imageToPrint.rect( ) );
    17. painter.drawImage( 0, 0, imageToPrint.toImage( ) );
    18. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas why my printer only seems to grab the first thing that I draw on the QGLWidget which are the grids. I draw the titles and data after drawing the grid lines by setting up their various viewports on the QGLWidget. Thanks for your help!!
    Last edited by wysota; 24th October 2006 at 21:54. Reason: missing [code] tags

Similar Threads

  1. QGLWidget renderText rotation
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 19th September 2007, 20:52
  2. QGLWidget on another QGLWiget
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2006, 09:59
  3. QGLWidget Problems
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2006, 22:06
  4. Replies: 0
    Last Post: 28th June 2006, 20:49

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
  •  
Qt is a trademark of The Qt Company.