PDA

View Full Version : select a printer question



impeteperry
29th January 2009, 17:32
Hi, I am running Ubuntu 8.10
I have a table written in Qt-4. (see attachment). I want to print the table part. I have a printer connected (Deskjet-5740). I am totally confused on how to start the printer module. (I had printed this type of program when I was using Qt-3.),

void PrintIndex::slotPb5()
{
QStringList temp;
QString path, k;

int corner[17][2];
int side, m, n, count, counter, base;
double a, b, x, y;
bool ret;

QPrinter myprinter; // = new QPrinter();
myprinter.setPageSize( QPrinter::Legal );
myprinter.setOrientation( QPrinter::Landscape );
myprinter.setColorMode( QPrinter::Color );
myprinter.setFullPage ( true );
ret = myprinter.setup();
if( ret == true )
{
QPainter p( &myprinter );

I would appreciate your help very much
Thank you

impeteperry
2nd February 2009, 06:43
i am sorry but the "code" I showed before was the wrong one. This one works.

Well, Lo and Behold, I found a program that answered my question
void BaseForm::paintEvent ( QPaintEvent * )
{
QStringList temp;
QString k;

int xs, xe, ys, ye;
int w, h;
int width, height;
int counter;
QPainter p ( this );
QPen pen;
QFont f;

if ( addressList.count() == 0 ) return;
f.setFamily ( "MuktiNarrow" );
f.setPointSize ( 10 );
p.setFont ( f );
pen.setBrush ( Qt::black );
p.setPen ( pen );
W = ui.frmLabelBoxes->width();
H = ui.frmLabelBoxes->height();

width = ( ( W-20 )-30 ) /3;
height = ( H - 115 ) /8;
counter = startCounter;
if ( clearFlag == true ) return;
for ( h = 0; h < 8; ++h )
{
for ( w = 0; w < 3; ++w )
{

k = addressList[counter++];
if ( counter > addressList.count()-1 ) return;
xs = 35 + w * ( 10 + width );
ys = 30 + h * ( 10 + height );
xe = width;
ye = height;
p.drawRect ( xs, ys, xe, ye );
p.fillRect ( xs+1, ys+1, xe-1, ye-1, Qt::white );
k = addressList[counter];
temp = k.split ( "\n" );
temp[0] = temp[0].remove( "*" ); /// remove the "*" beffore the name e xtenuion
count = temp.count();
for ( n = 0; n < count; ++n ) p.drawText ( xs + 5, ys + 13 * ( n + 1 ) , temp[n] );
endCounter = counter;
}
}
h = endCounter;
return;
}
Guess where I found it.!!!
In a program I wrote last year. What ever you do, don't get old.