Results 1 to 11 of 11

Thread: Printing problemQt3.3.5

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Printing problemQt3.3.5

    Hi guys,
    This is a problem related to printing.
    I have a QTextEdit in RichText format. I have some information on the textedit with different formats like font, color, size etc.

    According to my assumption whatever I type in the textEdit, the same should be printed on the printer page. But if I put some text at one end and some text at other end, the line gets wrapped to next line. Why is this unusual behaviour happening????

    I'm attaching a test.bmp file for clearer picture.

    thanks in advance
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Printing problemQt3.3.5

    Guys please help!!!!!

    I know people in this forum who are expert in Qt and I think this is not going to be tough for them to answer...

    Waiting for a reply

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

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by vermarajeev View Post
    if I put some text at one end and some text at other end, the line gets wrapped to next line.
    How do you put that text at the end of a line? Do you alter some tag attributes or just add white spaces?

  4. #4
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by jacek View Post
    How do you put that text at the end of a line? Do you alter some tag attributes or just add white spaces?
    Quote Originally Posted by jacek View Post
    How do you put that text at the end of a line? Do you alter some tag attributes or just add white spaces?
    Hi jacek, thanks for your reply

    Yes I just add white space by pressing spacebar on my keyboard and put the text at the end. The other interesting thing is that when I increase the point size of the font to say 18, the line doesnt get wrapped to next line. If I give small point size to say 9 then the line gets wrapped.

    As I know (WYSIWYG) "What you see is what you get", Whatever I type on TextEdit the same should be seen while printing also but I dont understand why the line is getting wrapped. The user wont be happy with this unusual behaviour

    I have also set the textEdit width and height to that of the printer. Here is a sample piece of code..

    Qt Code:
    1. p.begin( &printer );
    2. QPaintDeviceMetrics metrics( &printer );
    3. double dpmm = (double)metrics.width() / (double)metrics.widthMM(); //this is dots per mm
    4.  
    5. double aspect = ( (double)metrics.height() / (double)metrics.heightMM() ) //this is aspect ratio
    6. // Create a ratio which basically shows the size of the printer
    7. // canvas in comparison to the 72dpi postscript canvas.
    8. double ratio = PRINTERDPI/PostscriptDPI;
    9.  
    10. QPoint margin = mappings.marginPoint();
    11. int textEditHeight = 0;
    12. if(myTextEdit) //myTextEdit is the QTextEdit declared as a member variable
    13. textEditHeight = myTextEdit->height() * ratio ;
    14.  
    15. // print all the pages, looping by column first
    16. bool firstPage = true;
    17. for( int y = minimumPageNumber.y(); y <= maximumPageNumber.y(); ++y )
    18. for( int x = minimumPageNumber.x(); x <= maximumPageNumber.x(); ++x )
    19. {
    20. // do a newPage() before printing the current page
    21. // (except for the first page)
    22. if( firstPage )
    23. {
    24. firstPage = false;
    25. }
    26. else
    27. {
    28. printer.newPage();
    29. }
    30. changePage( x, y );
    31. //check if header is available to be printed
    32. if(myTextEdit)
    33. {
    34. int fontSz = (myTextEdit->fontInfo().pointSize());
    35. fontSz *= printerMap.getScaling(); //printerMap is mappings to printer where I scale
    36. //the font
    37. if( fontSz < 6 )
    38. fontSz = 6;
    39.  
    40. QFont headerFont = QFont( myTextEdit->family(), fontSz );
    41. p.setFont( headerFont );
    42.  
    43. QSimpleRichText richText( myTextEdit->text(),
    44. headerFont,
    45. myTextEdit->context(),
    46. myTextEdit->styleSheet(),
    47. myTextEdit->mimeSourceFactory(),
    48. myTextEdit->height() );
    49. richText.setWidth( &p, myTextEdit->width() );
    50. richText.draw( &p, margin.x(), margin.y(),headerView, colorGroup() );
    51. }
    To copy to clipboard, switch view to plain text mode 

    This is just a sample..... I have taken care of everything while printing but also the textEdit text gets wrapped... Please help me with this issue, I'll be thankful to you.

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

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by vermarajeev View Post
    Yes I just add white space by pressing spacebar on my keyboard and put the text at the end.
    In that case QTextEdit width must be exactly the same as paper width.

    Qt Code:
    1. QSimpleRichText richText( myTextEdit->text(),
    2. headerFont,
    3. myTextEdit->context(),
    4. myTextEdit->styleSheet(),
    5. myTextEdit->mimeSourceFactory(),
    6. myTextEdit->height() );
    7. richText.setWidth( &p, myTextEdit->width() );
    To copy to clipboard, switch view to plain text mode 
    IMO the problem is here. Printer pixels might have different size than screen pixels. Try multiplying myTextEdit->width() by (printer dpi / screen dpi).

  6. #6
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by jacek View Post
    In that case QTextEdit width must be exactly the same as paper width.
    IMO the problem is here. Printer pixels might have different size than screen pixels. Try multiplying myTextEdit->width() by (printer dpi / screen dpi).
    Hi jacek,

    I just tried out this
    Qt Code:
    1. QPaintDeviceMetrics metrics( &printer );
    2. QRect headerView = getHeaderRect(metrics);
    3.  
    4. QSimpleRichText richText( myTextedit->text(), headerFont, myTextedit->context(),
    5. myTextedit->styleSheet(),
    6. myTextedit->mimeSourceFactory(),
    7. headerView.height() );
    8. richText.setWidth( &p, headerView.width() );
    9. richText.draw( &p, margin.x(), margin.y(), headerView, colorGroup() );
    10.  
    11.  
    12. //defination
    13. QRect ChemCanvas::getHeaderRect(QPaintDeviceMetrics metrics)
    14. {
    15. QPoint margin = mappings.marginPoint();
    16. double ratio = mappings.dotsPerMm() * MM_PER_IN / PostscriptDPI;
    17. double headerHt;
    18. headerHt = (double)myTextedit->height();
    19. headerHt *= ratio;
    20.  
    21. QRect view( margin.x(), margin.y(), metrics.width()-2*margin.x() ,
    22. headerHt);
    23. return view;
    24. }
    To copy to clipboard, switch view to plain text mode 

    This is just a part of the code that I have written, I'm taking care of mapping printer width and height to that of the QTextEdit width and height.... but the result is same. The text gets wrapped to next line...

    Waiting eagerly for your suggestions

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

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by vermarajeev View Post
    double ratio = mappings.dotsPerMm() * MM_PER_IN / PostscriptDPI;
    double headerHt;
    headerHt = (double)myTextedit->height();
    headerHt *= ratio;
    Shouldn't it be "headerHt /= ratio;"?

    What is the value of "ratio"? Also check whether the resulting width isn't greater than page width.

  8. #8
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by jacek View Post
    Shouldn't it be "headerHt /= ratio;"?

    What is the value of "ratio"?
    Hi jacek,
    thanks for your reply

    "The ratio basically shows the size of the printer canvas in comparison to the 72dpi postscript canvas."

    The ratio's value is 8.3294 on my system. The headerHt's value in pixel is 45.00 which I map it to printer's height, so I have multiplied headerHt with ratio and the value headerHt is 374.826 after multiplying with ratio.

    Quote Originally Posted by jacek View Post
    Also check whether the resulting width isn't greater than page width.
    I have created a dialog called page setup where the user can change the page orientation, size etc to anything he/she wants. Now to reflect that on the Drawing area(QFrame) I have created a class called mappings which maps the user entered page orientation or size to that of the drawing area(QFrame).

    When I print the contents on the printer, first I'm getting page size and orientation of the printer, which I map that to the drawing area(QFrame). Those values I update in mappings class using setPageSize and setOrientation methods. then I make the drawing area(QFrame) as big as printer's size... print the entire information on the printer then resize the drawing area back to its normal size ( which is same as it was before printing ). This basically takes care of myTextEdit's width to be same as printer's width.

    Please let me know If i'm not clear.
    Waiting for a reply.

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

    Default Re: Printing problemQt3.3.5

    You could draw a rectangle which width and height are equal to a half of corresponding page dimension to verify that you set the size correctly.

    If everything is OK here, then I would check margins and font metrics.

  10. #10
    Join Date
    Sep 2006
    Posts
    339
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    15
    Thanked 21 Times in 16 Posts

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by jacek View Post
    You could draw a rectangle which width and height are equal to a half of corresponding page dimension to verify that you set the size correctly.

    If everything is OK here, then I would check margins and font metrics.
    Hi jacek, lets make things easier,

    There is a sample program provided in QT Assistant. This will help you to unserstand what my problem is???? I'm facing the same problem with my application

    Just run Qt/3.3.5/examples/textedit. Enter some text at the lefmost position, then enter some other text at rightmost position by hitting spacebar. Just print the contents on a pdf to check if it shows you the same thing. On my system the line is getting wrapped.

    Hope this will get you an exact idea about my problem

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

    Default Re: Printing problemQt3.3.5

    Quote Originally Posted by vermarajeev View Post
    Just run Qt/3.3.5/examples/textedit.
    You could have told me about this example earlier.

    After playing with it a bit, I think that the best solution is to make sure that logical width of text edit is constant and equal to page width. Unfortunately for some reason it's not enough, either the problem is in some rounding-off errors or font metrics are not the same on the screen and on the paper (which might mean that you have to use different font size).

Similar Threads

  1. Re: Printing in Qt
    By Jimmy2775 in forum Newbie
    Replies: 3
    Last Post: 12th July 2006, 23:00
  2. Replies: 0
    Last Post: 28th June 2006, 20:49
  3. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  4. Printing a PRN file on an NDPS printer
    By janca in forum General Discussion
    Replies: 4
    Last Post: 20th March 2006, 22:11
  5. Qt Printing on .ps
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 18th February 2006, 23:22

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.