IT实习技能提升第二弹


前言

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


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

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

1.qt窗口截屏

把qt窗口界面保存为图片

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

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

//保存文字输入信息
    QPrinter printer_text;
    printer_text.setOutputFormat(QPrinter::PdfFormat);  //设置输出格式为PDF
    printer_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<QActionGroup*> actionList;
 	QActionGroup                *   Mutual_Exclusion = nullptr;

2.mainwindow.cpp

void MainWindow::CreateMeasureActions()
{
	// PTP
    icon = 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 );

    // 2048KHz
    icon = 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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值