PDA

View Full Version : WIN32 + Barcode



aekilic
11th May 2009, 19:47
Does anybody know how could I print barcodes with qt? Or Is there any example for this?

Lykurg
11th May 2009, 20:08
Use a free barcode font, put it inside your application, use QPixmap, QPainter, drawText and use the image everywhere you want.

aekilic
12th May 2009, 13:15
Thank you, but is there any example who did this before? Where could I find a free font?

Lykurg
12th May 2009, 16:44
Thank you, but is there any example who did this before?
Come on, that's not that difficult!

QString text = "CODE";
QFont font("Trebuchet MS");
QFontMetrics fm(font);
QRect bound = fm.boundingRect(text);
bound.moveTo(0,0);
QPixmap pix(bound.size());
pix.fill(Qt::white);
QPainter p(&pix);
p.setFont(font);
p.setPen(QPen(Qt::black,1,Qt::SolidLine));
p.drawText(bound, Qt::AlignCenter, text);
p.end();


Where could I find a free font?
Google -> barcode font free : Code 39

gwyn
12th May 2009, 23:39
The answer would depend on what barcode you need to use. As far as I know Code 39 is simple enough as it has a 1:1 relationship from character to glyph. On the other hand EAN-13/UPC which is used in commerce has a complex relationship where the final glyph depends on the original character, its position in the string, its parity and the phase of the moon.

As it happens, I have just finished a first attempt at printing EAN-13 barcodes to a laser printer and had success both reading and scanning the results.

If you are interested I can send you a copy of the class - it works but it could probably be improved. Also, the moon-phase bit is not yet implemented ;)

Lykurg
13th May 2009, 11:02
If you are interested I can send you a copy of the class - it works but it could probably be improved.

Maybe others also would like to see the code. If it is no company secret It would be nice if you could post it here or create a new wiki entry for that.

talk2amulya
13th May 2009, 11:27
yes, we do need a new wiki entry..hasnt been any new one for a LONG time..plus it would be interesting to know how u maintained EAN-13/UPC, cuz it sounds hard

gwyn
13th May 2009, 13:40
ok, I'll attempt a wiki then repost here when done.

gwyn
14th May 2009, 00:01
For all interested parties the article is up on the wiki under examples.

I would appreciate proof-reading and comments

Cheers all

talk2amulya
14th May 2009, 10:38
great article! well documented, very informative..superb job..thanks gwyn

Lykurg
14th May 2009, 10:44
Thanks for the article, I just have added a function to change the barcode after the instance was created.

gwyn
14th May 2009, 16:08
Glad you like it. If this meets aekilic's needs perhaps the thread should be marked as solved?

aekilic
14th May 2009, 21:12
that will solve all my problems..... thank you very very much