代码拉取完成,页面将自动刷新
同步操作将从 dush/QRCodeTools 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow) {
relQRImage = nullptr;
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
#include "QDebug"
void MainWindow::on_pushButton_clicked() {
QRecLevel ecl = QRecLevel(ui->ecLevel->value());
QString txt = ui->text->toPlainText();
txt = txt.trimmed();
if (txt.isEmpty()) {
return;
}
if (relQRImage != nullptr) {
delete this->relQRImage;
}
QRcode* qrcode = QRcode_encodeString(txt.toStdString().data(), 1, ecl, QR_MODE_8, 1);
this->relQRImage = drawQRCode(qrcode);
this->ui->view->setPixmap(this->relQRImage->scaled(250, 250, Qt::KeepAspectRatio));
}
using namespace std;
QPixmap* MainWindow::drawQRCode(QRcode *qrcode) {
int w = qrcode->width;
QPixmap *map = new QPixmap(w * w, w * w);
QPainter painter(map);
map->fill(QColor(255, 255, 255));
// ui->view->activateWindow();
// 反走样
// painter.setRenderHint(QPainter::Antialiasing, true);
// 设置画笔颜色、宽度
//painter.setPen(QPen(QColor(0, 160, 230), 5));
// 设置画刷颜色
QColor h(0, 0, 0);
if (qrcode == nullptr) {
return map;
}
for (int i = 0; i < w; i++) {
for (int j = 0; j < w; j++) {
unsigned char d = qrcode->data[i * w + j];
if (d & 0x01) {
painter.setBrush(h);
painter.drawRect(i * w, j * w, w, w);
}
}
}
return map;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。