Ai
1 Star 0 Fork 4

hb/QrencodeQt

forked from 调试中.../QrencodeQt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mainwindow.cpp 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
yao.fu 提交于 2018-05-11 20:05 +08:00 . init code
#include <QPainter>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qrencode/qrencode.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString text = ui->textEdit->toPlainText();
QRcode *qrcode;
qrcode = QRcode_encodeString(text.toStdString().c_str(), 2, QR_ECLEVEL_Q, QR_MODE_8, 1);
qint32 temp_width=ui->label->width(); //二维码图片的大小
qint32 temp_height=ui->label->height();
qint32 qrcode_width = qrcode->width > 0 ? qrcode->width : 1;
double scale_x = (double)temp_width / (double)qrcode_width; //二维码图片的缩放比例
double scale_y =(double) temp_height /(double) qrcode_width;
QImage mainimg=QImage(temp_width,temp_height,QImage::Format_ARGB32);
QPainter painter(&mainimg);
QColor background(Qt::white);
painter.setBrush(background);
painter.setPen(Qt::NoPen);
painter.drawRect(0, 0, temp_width, temp_height);
QColor foreground(Qt::black);
painter.setBrush(foreground);
for( qint32 y = 0; y < qrcode_width; y ++)
{
for(qint32 x = 0; x < qrcode_width; x++)
{
unsigned char b = qrcode->data[y * qrcode_width + x];
if(b & 0x01)
{
QRectF r(x * scale_x, y * scale_y, scale_x, scale_y);
painter.drawRects(&r, 1);
}
}
}
QPixmap mainmap=QPixmap::fromImage(mainimg);
ui->label->setPixmap(mainmap);
ui->label->setVisible(true);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hubean/QrencodeQt.git
git@gitee.com:hubean/QrencodeQt.git
hubean
QrencodeQt
QrencodeQt
master

搜索帮助