吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2596|回复: 6
收起左侧

[会员申请] 申请会员ID:dannialzone【申请通过】

[复制链接]
吾爱游客  发表于 2022-1-6 11:14
1、申请ID:dannialzone
2、个人邮箱:dannialzone@163.com
3、原创软件:大江阿里京东箱签快速打印系统

㈠开发此程序的初衷,因为经常往阿里和京东发货,需要在箱面写明箱内装的是何物品,经常在标签贴上手写非常的麻烦,于是有了开发这款软件的想法;
读取源数据方面,是同事传给我的excel表格,所以需要先读取excel文件的内容,并加载到程序里的表格中,如图
启动软件
1.jpg
读取表格
2.jpg
读取excel表格数据代码如下
[C++] 纯文本查看 复制代码
int DoExcelWork::onBtnReadExcelClicked()
{
        if (!ui.radioBtnAli->isChecked() && !ui.radioBtnJD->isChecked())
        {
                QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("未选择京东或是阿里!"));
                return -1;
        }
        //选择了京东
        if (ui.radioBtnJD->isChecked())
        {
                bool isOpen = ExcelBase::me()->openExcelFile(ui.lineExcelPath->text(), 1);
                //先判断要读取的表格在哪个sheet
                if (isOpen)
                {
                        QString text = ExcelBase::me()->getCellValue(1, 1);

                        switch (text.contains(QString::fromLocal8Bit("京东")))
                        {
                        case false:
                                ExcelBase::me()->openExcelFile(ui.lineExcelPath->text(), 2);
                        case true:
                                int rowsTotal = ExcelBase::me()->getRowsTotal();    //获取数据总行数
                                
                                //如果有数据先删除所有数据行
                                if (ui.tableWidget->rowCount())
                                {
                                        for (int n = 0; n < ui.tableWidget->rowCount(); n++)
                                                ui.tableWidget->removeRow(0);
                                }
                                ui.tableWidget->setRowCount(rowsTotal - 2);
                                int row = 0;
                                for (int i = 3; i <= rowsTotal; i++)
                                {
                                        //获取订单号
                                        QString orderNumber = ExcelBase::me()->getCellValue(i, 1).trimmed();

                                        //获取商品名称
                                        QString goodsName = ExcelBase::me()->getCellValue(i, 2);
                                        if (goodsName.contains(QString::fromLocal8Bit("万通")))
                                        {
                                                goodsName = goodsName.replace(QString::fromLocal8Bit("万通"), "").trimmed();
                                        }
                                        //获取仓库
                                        QString warehouse = ExcelBase::me()->getCellValue(i, 3).trimmed();

                                        //获取详细地址
                                        QString addr = ExcelBase::me()->getCellValue(i, 4).trimmed();

                                        //获取订单数量
                                        QString orderAmount = ExcelBase::me()->getCellValue(i, 5).trimmed();

                                        //流向
                                        QString flowDirection = addr + " " + warehouse;

                                        //将获取到的文本写入到表格中
                                        ui.tableWidget->setItem(row, 0, new QTableWidgetItem(orderNumber));
                                        ui.tableWidget->setItem(row, 1, new QTableWidgetItem(goodsName));
                                        ui.tableWidget->setItem(row, 2, new QTableWidgetItem(flowDirection));
                                        ui.tableWidget->setItem(row, 3, new QTableWidgetItem(orderAmount));

                                        //设置居中
                                        ui.tableWidget->item(row, 0)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidget->item(row, 1)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidget->item(row, 2)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidget->item(row, 3)->setTextAlignment(Qt::AlignCenter);
                                        row++;
                                }
                                ui.statusBar->showMessage(QString::fromLocal8Bit("成功读取") +
                                        QString::number(rowsTotal - 2) + QString::fromLocal8Bit("条数据"), 0);
                                break;
                        }
                }
        }
        //选择了阿里
        else if (ui.radioBtnAli->isChecked())
        {
                bool isOpen = ExcelBase::me()->openExcelFile(ui.lineExcelPath->text(), 1);
                //先判断要读取的表格在哪个sheet
                if (isOpen)
                {
                        QString text = ExcelBase::me()->getCellValue(1, 1);

                        switch (text.contains(QString::fromLocal8Bit("阿里")))
                        {
                        case false:
                                ExcelBase::me()->openExcelFile(ui.lineExcelPath->text(), 2);
                        case true:
                                int rowsTotal = ExcelBase::me()->getRowsTotal();    //获取数据总行数
                                
                                //如果有数据先删除所有数据行
                                if (ui.tableWidgetAli->rowCount())
                                {
                                        for (int n = 0; n < ui.tableWidgetAli->rowCount(); n++)
                                                ui.tableWidgetAli->removeRow(0);
                                }
                                ui.tableWidgetAli->setRowCount(rowsTotal - 2);
                                int row = 0;
                                for (int i = 3; i <= rowsTotal; i++)
                                {
                                        //获取序号
                                        QString number = ExcelBase::me()->getCellValue(i, 1).trimmed();

                                        //获取路线
                                        QString flowDirection = ExcelBase::me()->getCellValue(i, 4).trimmed();                
                                        if (flowDirection == "")        
                                                continue;                        
                                        
                                        //获取商品名称
                                        QString goodsName = ExcelBase::me()->getCellValue(i, 5);
                                        if (goodsName.contains(QString::fromLocal8Bit("(十大连锁)")))
                                        {
                                                goodsName = goodsName.replace(QString::fromLocal8Bit("(十大连锁)"), "").trimmed();
                                        }
                                        else if (goodsName.contains(QString::fromLocal8Bit("(十大连锁)")))
                                        {
                                                goodsName = goodsName.replace(QString::fromLocal8Bit("(十大连锁)"), "").trimmed();
                                        }
                                        else if (goodsName.contains(QString::fromLocal8Bit("(电商)")))
                                        {
                                                goodsName = goodsName.replace(QString::fromLocal8Bit("(电商)"), "").trimmed();
                                        }
                                        else if (goodsName.contains(QString::fromLocal8Bit("(电商)")))
                                        {
                                                goodsName = goodsName.replace(QString::fromLocal8Bit("(电商)"), "").trimmed();
                                        }
                                        //获取包装规格
                                        QString spec = ExcelBase::me()->getCellValue(i, 6).trimmed();

                                        //获取总盒数
                                        QString totalBox = ExcelBase::me()->getCellValue(i, 7).trimmed();

                                        //获取件数
                                        QString piece = ExcelBase::me()->getCellValue(i, 8).trimmed();

                                        //将获取到的文本写入到表格中
                                        ui.tableWidgetAli->setItem(row, 0, new QTableWidgetItem(number));
                                        ui.tableWidgetAli->setItem(row, 1, new QTableWidgetItem(flowDirection));
                                        ui.tableWidgetAli->setItem(row, 2, new QTableWidgetItem(goodsName));
                                        ui.tableWidgetAli->setItem(row, 3, new QTableWidgetItem(spec));
                                        ui.tableWidgetAli->setItem(row, 4, new QTableWidgetItem(totalBox));
                                        ui.tableWidgetAli->setItem(row, 5, new QTableWidgetItem(piece));

                                        //设置居中
                                        ui.tableWidgetAli->item(row, 0)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidgetAli->item(row, 1)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidgetAli->item(row, 2)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidgetAli->item(row, 3)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidgetAli->item(row, 4)->setTextAlignment(Qt::AlignCenter);
                                        ui.tableWidgetAli->item(row, 5)->setTextAlignment(Qt::AlignCenter);
                                        row++;
                                }
                                ui.statusBar->showMessage(QString::fromLocal8Bit("成功读取") +
                                        QString::number(rowsTotal - 2) + QString::fromLocal8Bit("条数据"), 0);
                                break;
                        }
                }
        }
        return 0;
}

②数据读取完成后,点击预览打印,预览打印功能通过绘制实现,指定标签的大小,位置,并在其上面绘制文字,如图:

3.jpg
代码实现如下:
[C++] 纯文本查看 复制代码
int DoExcelWork::onBtnPrintClicked()
{
        if (!ui.tableWidget->rowCount() && !ui.tableWidgetAli->rowCount())
                return -1;
        QPrinter printer(QPrinter::HighResolution);
        
        //自定义纸张大小,特别重要,不然预览效果极差
        printer.setPageSize(QPrinter::B5);
        //printer.setPaperSize(QSizeF(600, 800), QPrinter::Point);
        QPrintPreviewDialog preview(&printer, this);// 创建打印预览对话框

        preview.setMinimumSize(600, 800);
        /*
        * QPrintPreviewDialog类提供了一个打印预览对话框,里面功能比较全,
        * paintRequested(QPrinter *printer)是系统提供的,
        * 当preview.exec()执行时该信号被触发,
        * drawPic(QPrinter *printer)是自定义的槽函数,图像的绘制就在这个函数里。
        */
        connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(drawPic(QPrinter*)));
        preview.exec();

        return 0;
}

[C++] 纯文本查看 复制代码
void DoExcelWork::drawPic(QPrinter *printer)
{
        QPixmap pix = QPixmap(600, 800);
        //这个函数算是画模板的函数吧,毕竟打印时有模板的
        createPix(&pix);
        
        //纵向:Portrait 横向:Landscape
        printer->setOrientation(QPrinter::Portrait);
        
        //设置纸张大小及页边距
        printer->setPageSize(QPrinter::B5);
        printer->setPageMargins(1, 1, 25.5, 13.5, QPrinter::Millimeter);  //好像没什么用

        //获取界面的图片
        QPainter painterPixmap(printer);
        QRect rect = painterPixmap.viewport();
        QSize size = pix.size();
        size.scale(rect.size(), Qt::KeepAspectRatio);//此处保证图片显示完整
        painterPixmap.setViewport(rect.x(), rect.y(), size.width(), size.height());
        painterPixmap.setWindow(pix.rect());
        //painterPixmap.drawPixmap(0, 0, pix); //使用后字体锯齿严重

        // 设置画笔颜色、宽度
        painterPixmap.setPen(QPen(QColor(255, 255, 255), 2));

        // 设置画刷颜色
        painterPixmap.setBrush(QColor(255, 255, 255));
        QRect rct(0, 0, 600, 800);

        //整张图设置画刷白底
        painterPixmap.fillRect(rct, QColor(255, 255, 255));
        painterPixmap.drawRect(rct);

        //画数据部分的线条
        painterPixmap.setPen(QPen(QColor(0, 0, 0), 1));
        QFont font;
        font.setFamily("Microsoft YaHei");
        font.setPointSize(5);
        font.setStyleStrategy(QFont::PreferAntialias);
        painterPixmap.setFont(font);

        //将列表数据绘制在模板上,导入的是京东表格
        if (ui.radioBtnJD->isChecked() && ui.tableWidget->rowCount() != 0)
        {
                int rowCount = ui.tableWidget->rowCount();
                int count = 0;

                for (int i = 0; i < rowCount; i++)
                {
                        switch (count)
                        {
                        case 0:
                                //第一行 第一列
                                painterPixmap.drawText(0, 0, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(0, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(0, 50, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(0, 90, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 1:
                                //第一行 第二列
                                painterPixmap.drawText(278, 0, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(278, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(278, 50, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(278, 90, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 2:
                                //第二行 第一列
                                painterPixmap.drawText(0, 150, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(0, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(0, 200, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(0, 240, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 3:
                                //第二行 第二列
                                painterPixmap.drawText(278, 150, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(278, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(278, 200, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(278, 240, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 4:
                                //第三行 第一列
                                painterPixmap.drawText(0, 290, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(0, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(0, 340, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(0, 380, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 5:
                                //第三行 第二列
                                painterPixmap.drawText(278, 290, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(278, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(278, 340, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(278, 380, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 6:
                                //第四行 第一列
                                painterPixmap.drawText(0, 430, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(0, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(0, 480, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(0, 520, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 7:
                                //第四行 第二列
                                painterPixmap.drawText(278, 430, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(278, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(278, 480, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(278, 520, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 8:
                                //第五行 第一列
                                painterPixmap.drawText(0, 570, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(0, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(0, 620, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(0, 660, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        case 9:
                                //第五行 第二列
                                painterPixmap.drawText(278, 570, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("采购单号:") + ui.tableWidget->item(i, 0)->text());
                                painterPixmap.drawText(278, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("流向:") + ui.tableWidget->item(i, 2)->text());
                                painterPixmap.drawText(278, 620, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("箱数:"));
                                painterPixmap.drawText(278, 660, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidget->item(i, 1)->text());
                                count++;
                                break;
                        }
                        if (count == 10)
                        {
                                count = 0;
                                printer->newPage();
                        }
                }
        }
        
        //导入的是阿里表格
        if (ui.radioBtnAli->isChecked() && ui.tableWidgetAli->rowCount() != 0)
        {
                int rowCount = ui.tableWidgetAli->rowCount();
                int count = 0;

                for (int i = 0; i < rowCount; i++)
                {
                        if (! ui.tableWidgetAli->item(i, 0))
                                continue;
                        if (ui.tableWidgetAli->item(i, 4)->text().toInt() % ui.tableWidgetAli->item(i, 3)->text().toInt() == 0)
                                continue;
                        switch (count)
                        {
                        case 0:
                        {
                                //第一行 第一列
                                painterPixmap.drawText(0, 0, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(0, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;
                                        painterPixmap.drawText(0, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(0, 65, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 1:
                        {
                                //第一行 第二列
                                painterPixmap.drawText(278, 0, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(278, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;
                                        painterPixmap.drawText(278, 25, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(278, 65, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 2:
                        {
                                //第二行 第一列
                                painterPixmap.drawText(0, 150, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(0, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;
                                        painterPixmap.drawText(0, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(0, 215, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 3:
                        {
                                //第二行 第二列
                                painterPixmap.drawText(278, 150, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(278, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(278, 175, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(278, 215, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 4:
                        {
                                //第三行 第一列
                                painterPixmap.drawText(0, 290, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(0, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(0, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(0, 355, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 5:
                        {
                                //第三行 第二列
                                painterPixmap.drawText(278, 290, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(278, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(278, 315, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(278, 355, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 6:
                        {
                                //第四行 第一列
                                painterPixmap.drawText(0, 430, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(0, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(0, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(0, 495, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 7:
                        {
                                //第四行 第二列
                                painterPixmap.drawText(278, 430, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(278, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(278, 455, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(278, 495, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 8:
                        {
                                //第五行 第一列
                                painterPixmap.drawText(0, 570, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(0, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(0, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(0, 635, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        case 9:
                        {
                                //第五行 第二列
                                painterPixmap.drawText(278, 570, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("药品名称:") + ui.tableWidgetAli->item(i, 2)->text());

                                //件数
                                double piece = ui.tableWidgetAli->item(i, 5)->text().toDouble();
                                if (piece < 1)
                                {
                                        painterPixmap.drawText(278, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + ui.tableWidgetAli->item(i, 4)->text());
                                }
                                else if (piece > 1)
                                {
                                        int totalBox = ui.tableWidgetAli->item(i, 4)->text().toInt();  //总盒数
                                        int spec = ui.tableWidgetAli->item(i, 3)->text().toInt();      //包装规格数
                                        int boxRet = totalBox - spec * (int)piece;                     //取得实际需包装的盒数
                                        painterPixmap.drawText(278, 595, 272, 136, Qt::AlignLeft, QString::fromLocal8Bit("盒数:") + QString::number(boxRet));
                                }

                                painterPixmap.drawText(278, 635, 272, 136, Qt::AlignLeft, ui.tableWidgetAli->item(i, 0)->text() + " " + ui.tableWidgetAli->item(i, 1)->text());
                                count++;
                        }
                                break;
                        }
                        if (count == 10)
                        {
                                count = 0;
                                printer->newPage();
                        }
                }
        }
        painterPixmap.end();
}

③点击打印后,标签贴纸效果如下:
QQ截图20220106111016.jpg

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Hmily 发表于 2022-1-6 15:21
I D:dannialzone
邮箱:dannialzone@163.com

申请通过,欢迎光临吾爱破解论坛,期待吾爱破解有你更加精彩,ID和密码自己通过邮件密码找回功能修改,请即时登陆并修改密码!
登陆后请在一周内在此帖报道,否则将删除ID信息。
吾爱游客  发表于 2022-1-6 21:14
dannialzone 发表于 2022-1-6 21:32
感谢吾爱破解,感谢版主大大,我来报道啦!
dannialzone 发表于 2022-1-8 17:26
我来报个道~~
dannialzone 发表于 2022-1-10 09:33
来了来了,报到
dannialzone 发表于 2022-1-10 09:39
Hmily 发表于 2022-1-6 15:21
I D:dannialzone
邮箱:

来报到了~~,感谢Hmily
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 12:36

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表