IT实习技能提升第二弹
创始人
2025-05-29 14:45:18

文章目录

  • 前言
  • 一、Qt读写pdf文件(将文字图片混合加入pdf文件中)
      • 1.qt窗口截屏
      • 2.将文字信息写入pdf文件中
      • 3.将图像信息保存到pdf文件中
  • 二、新建一个窗口
      • 1.使用QWidget
      • 2.在窗口中添加控件
  • 三、日期时间
      • 1.获取当前日期
      • 2.获取当前时间
  • 四、控件之间互斥
      • 1.mainwindow.h
      • 2.mainwindow.cpp
      • 3.工具条中加进去控件
  • 总结


前言

新入职的码农,嵌入式软件方向


提示:以下是本篇文章正文内容,下面案例可供参考

一、Qt读写pdf文件(将文字图片混合加入pdf文件中)

1.qt窗口截屏

把qt窗口界面保存为图片

QPixmap pixmap = this->grab();  //获取界面的图片

2.将文字信息写入pdf文件中

//保存文字输入信息QPrinter printer_text;printer_text.setOutputFormat(QPrinter::PdfFormat);  //设置输出格式为PDFprinter_text.setOutputFileName(savefile_name);  //设置输出路径QPainter painter_text;painter_text.begin(&printer_text);QPoint point(10,10);QString msg = (SubmittingunitLabel->text()).append(SubmittingunitEdit->text());msg.append("     ");point.setY(30);msg.append((EquipmentmodelLabel->text())).append(EquipmentmodelEdit->text());msg.append("     ");point.setY(50);msg.append((TesttimeLabel->text())).append(TesttimeEdit->text());painter_text.drawText(point, msg);msg.clear();

3.将图像信息保存到pdf文件中

	QRect rect = painter_text.viewport();float multiple = (double(rect.width()) / pixmap.width());float yMultiple = (double(rect.height()) / pixmap.height());float fMin = (multiple < yMultiple) ? multiple : yMultiple;painter_text.scale(fMin, fMin); //将图像(所有要画的东西)在pdf上放大multiple-1倍point.setY(50+20);painter_text.drawPixmap(0, 90, pixmap.width(), pixmap.height(), pixmap);  //在指定位置画图painter_text.end();

二、新建一个窗口

1.使用QWidget

代码如下(示例):

QWidget *previeWidget = new QWidget();
previeWidget->show();

2.在窗口中添加控件

代码如下(示例):

QLabel *messageLabel = new QLabel(previeWidget);

三、日期时间

1.获取当前日期

	QDate date = QDate::currentDate();QString file_date = date.toString("yyyy-MM-dd");

2.获取当前时间

	QTime time = QTime::currentTime();QString file_time = time.toString("hh-mm-ss");

四、控件之间互斥

1.mainwindow.h

public slots:void m_pActionMeasure_PTPChecked();void m_pActionMeasure_2048KHzChecked();void compareChecked(QAction *newChecked);signals:void selectedID(QAction *newChecked);private:QAction *buffer;QList actionList;QActionGroup                *   Mutual_Exclusion = nullptr;

2.mainwindow.cpp

void MainWindow::CreateMeasureActions()
{// PTPicon = QIcon(":/images/N_PTP.png");m_pActionMeasure_PTP = new QAction( icon, "PTP", this );connect( m_pActionMeasure_PTP, &QAction::triggered,this,&MainWindow::slot_StartMeasurePTP);m_pActionMeasure_PTP->setCheckable( true );// 2048KHzicon = QIcon(":/images/N_2048.png");m_pActionMeasure_2048KHz = new QAction( icon, "2048KHz", this );connect( m_pActionMeasure_2048KHz, &QAction::triggered,this,&MainWindow::slot_StartMeasure2048kHz);m_pActionMeasure_2048KHz->setCheckable( true );//实现曲线显示互斥buffer = 0;Mutual_Exclusion = new QActionGroup(this);Mutual_Exclusion->addAction(m_pActionMeasure_PTP);Mutual_Exclusion->addAction(m_pActionMeasure_2048KHz);connect(m_pActionMeasure_PTP,SIGNAL(triggered()),this,SLOT(m_pActionMeasure_PTPChecked()));connect(m_pActionMeasure_2048KHz,SIGNAL(triggered()),this,SLOT(m_pActionMeasure_2048KHzChecked()));connect(this,SIGNAL(selectedID(QAction*)),this,SLOT(compareChecked(QAction*)));
}void MainWindow::compareChecked(QAction *newChecked)
{if (newChecked != buffer) {if (buffer != 0)buffer->setChecked(false);buffer = newChecked;}
}
void MainWindow::m_pActionMeasure_2048KHzChecked()
{if(m_pActionMeasure_2048KHz->isChecked()){m_printMsgName = "2048KHz";emit selectedID(m_pActionMeasure_2048KHz);}
}
void MainWindow::m_pActionMeasure_PTPChecked()
{if(m_pActionMeasure_PTP->isChecked()){m_printMsgName = "PTP";emit selectedID(m_pActionMeasure_PTP);}
}

3.工具条中加进去控件

	m_pToolbar->addAction( m_pActionMeasure_PTP );m_pToolbar->addAction( m_pActionMeasure_2048KHz );

总结

1.越往后越得心应手
2.实现功能真的很有成就感
3.及时反馈问题,遇到不会的功能,把你的困扰讲给老板听,会理解的(他也会想他刚入职是什么样子的hhh)

相关内容

热门资讯

视频丨从“会种地”到“慧种地”... 农田一边连着农民的收成一边连着百姓的饭碗今年的农田“更新”了啥?看看大家怎么说01:34南京浦口众鑫...
俄媒曝拉夫罗夫揪出美国间谍 (来源:环球时报)转自:环球时报 【#俄媒曝拉夫罗夫揪出...
突发:俄罗斯发动大规模空袭 当地时间13日,乌克兰敖德萨州州长奥列格·基佩尔表示,敖德萨遭受了俄罗斯大规模的空袭。目前,敖德萨大...
一事业单位职工长期失联,被辞退 (来源:上观新闻)河南平顶山市戏剧研究中心12月9日在《平顶山日报》发布辞退公告。被辞退对象为平顶山...
企业安全生产责任制管理制度 安... 企业安全生产责任制管理制度 一、主题内容与适用范围 本责任制规定了各级领导干部、职能...