Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, February 2007
Basic Qprinter question


Message 1 in thread

Thank you for reading this.

I'm trying to print out a 12 x 12 matrix of QChars using the default
settings of the printer and QPrinter, nothing fancy at this stage.

The matrix prints as a black 6mm block so I have simplified what I'm trying 
to
achieve by replacing the matrix with a string.

Instead of printing "test" on two separate lines I seem to be getting the
word over typed twice on the same spot on the page. I have looked at several 
Qt example files and taken what I think I need.

Can someone point out what I'm doing wrong?

void wordsearch::print()
{
     if (printer->setup(this))
    {
        QPainter paint;
        if(!paint.begin(printer))
            return;

        for(int row = 0; row < 2; row++)
            paint.drawText(0, row + 150, "test");
    }
}

Regards,
Phil.

--
 [ signature omitted ] 

Message 2 in thread

Looks ok for me. Maybe a problem with your setup? You could try to set
your print parameters manually (printer->setPagesize(...), 
printer->setResolution(...), etc.). Just to see if it makes a 
difference.

Guido

> Can someone point out what I'm doing wrong?
> 
> void wordsearch::print()
> {
>     if (printer->setup(this))
>    {
>        QPainter paint;
>        if(!paint.begin(printer))
>            return;
> 
>        for(int row = 0; row < 2; row++)
>            paint.drawText(0, row + 150, "test");
>    }
> }

--
 [ signature omitted ] 

Message 3 in thread

Phil wrote:

> Can someone point out what I'm doing wrong?
> 
> void wordsearch::print()
> {
>      if (printer->setup(this))
>     {
>         QPainter paint;
>         if(!paint.begin(printer))
>             return;
> 
>         for(int row = 0; row < 2; row++)
>             paint.drawText(0, row + 150, "test");
>     }
> }

Surely you meant to write this:

             paint.drawText(0, row * 150, "test");

David

--
 [ signature omitted ] 

Message 4 in thread

> Surely you meant to write this:
> 
>              paint.drawText(0, row * 150, "test");

Outch!


--
 [ signature omitted ] 

Message 5 in thread

----- Original Message ----- 
From: "David Boddie" <dboddie@xxxxxxxxxxxxx>
To: <qt-interest@xxxxxxxxxxxxx>
Sent: Tuesday, February 06, 2007 11:14 PM
Subject: Re: Basic Qprinter question


>
> Surely you meant to write this:
>
>             paint.drawText(0, row * 150, "test");
>

Thank you Guido and David for your replies. I don't know why I didn't see
that myself. By the way, *20 works well.

Now I have another related problem that I will post in a separate message 
(Calling a function from a dialog window).

Regards,
Phil.

--
 [ signature omitted ] 

Message 6 in thread

> >
> >Surely you meant to write this:
> >
> >            paint.drawText(0, row * 150, "test");
> >

>I don't know why I didn't see that myself. 

Easy. It was syntactically correct code. So it did not stuck out and 
most people just 'translate' it to the correct meaning in the head. 
Especially the original coder.

I really wish there was some coding technique, which helps to prevent 
such sort of mistakes. 

Guido
 


--
 [ signature omitted ]