qt实现小票打印

1.需求

需要实现订单结算后的小票打印,要求能打印商品数据和结算数据及将小票号打印成条码,退货或查询时能通过扫描枪扫描条码快速查询到订单信息

2.解决

1.通过将数据转化为html后调用qt进行打印,打印机无法打印img标签中的条码
2.通过将数据转化为html,将条码直接绘制的方法实现了需求

3.代码

Barcode.h
// Barcode.h: interface for the CBarcode class.
//
//  Copyright 2002 Neil Van Eps
//
//////////////////////////////////////////////////////////////////////
#ifndef BARCODE_H
#define BARCODE_H
#include <QString>
#include <QPainter>

// bblib.h
//  must put build number define on third line
#define BUILDNUM 7
//
//
//  Copyright 2002 Neil Van Eps
//

enum Symbology
{
    RATIONALCODABAR,
    TRADITIONALCODABAR,
    I2OF5,
    CODE39,
    COD128,
    UPCEAN,
    CODE93
};

#define     COLORWHITE  0x00FFFFFF
#define     COLORBLACK  0x00000000

class CBarcode  
{
public:
    CBarcode();
    void    LoadData(QString csMessage, const QString &strImagePath, double dNarrowBar, double dFinalHeight, int nStartingXPixel, int nStartingYPixel, double dRatio = 1.0);
    virtual void DrawBitmap(QPainter *painter = nullptr) = 0;
    //virtual void BitmapToClipboard() = 0;
    virtual ~CBarcode();
    long    GetBarcodePixelWidth();
    long    GetBarcodePixelHeight();
protected:
    QString m_csMessage;
    //HDC       m_hDC;     
    QString m_strImagePath;
    long    m_nFinalBarcodePixelWidth;
    long    m_nNarrowBarPixelWidth;
    long    m_nPixelHeight;
    long    m_nStartingXPixel;
    long    m_nStartingYPixel;
    long    m_nSymbology;
    long    m_nWideBarPixelWidth;
    virtual void DrawPattern(QString csPattern, QPainter *painter) = 0;
};

#endif // !defined(AFX_BARCODE_H__C5D7FCDA_5C8F_4244_AF95_33D6FA93F8EB__INCLUDED_)
Barcode.cpp
// Barcode.cpp: implementation of the CBarcode class.
//
//  Copyright 2002 Neil Van Eps
//
//////////////////////////////////////////////////////////////////////
#include "Barcode.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBarcode::CBarcode()
{

}

CBarcode::~CBarcode()
{

}

////////////////////////////////////////////////////////////////////////////////////
//
//  Name:
//      LoadData()
//
//  Description:
//
//
//  Arguments:
//
//
//  Return:
//
//
//  Called by:
//
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值