新入职的码农,嵌入式软件方向
提示:以下是本篇文章正文内容,下面案例可供参考
把qt窗口界面保存为图片
QPixmap pixmap = this->grab(); //获取界面的图片
//保存文字输入信息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();
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();
代码如下(示例):
QWidget *previeWidget = new QWidget();
previeWidget->show();
代码如下(示例):
QLabel *messageLabel = new QLabel(previeWidget);
QDate date = QDate::currentDate();QString file_date = date.toString("yyyy-MM-dd");
QTime time = QTime::currentTime();QString file_time = time.toString("hh-mm-ss");
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;
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);}
}
m_pToolbar->addAction( m_pActionMeasure_PTP );m_pToolbar->addAction( m_pActionMeasure_2048KHz );
1.越往后越得心应手
2.实现功能真的很有成就感
3.及时反馈问题,遇到不会的功能,把你的困扰讲给老板听,会理解的(他也会想他刚入职是什么样子的hhh)