QT dialog一种使用方法

来源:互联网 发布:中国狙击步枪 知乎 编辑:程序博客网 时间:2024/06/13 23:55
// 导出视频片段void extractTrajectoryWidget::exportAviSegment(){//设计一个弹出widget,包括内容:导出名称,存储路径(可选择)QDialog*dialog = new QDialog(this);dialog->window()->setWindowTitle(QStringLiteral("导出配置"));QLineEdit* aviFileNameLineEdit = new QLineEdit;// 导出视频片段保存路径/*QLineEdit**/aviFilePathLineEdit = new QLineEdit;// 设置为成员函数,为了槽能够操作这个变量aviFilePathLineEdit->setText(pGparam->synVideoPath.c_str());QPushButton*selectPathButton = new QPushButton(QStringLiteral("选择"));connect(selectPathButton,SIGNAL(clicked()),this,SLOT(selectSavePath()));{QVBoxLayout* v11Layout = new QVBoxLayout;v11Layout->addWidget(new QLabel(QStringLiteral("保存文件名:")));v11Layout->addWidget(new QLabel(QStringLiteral("存储路径:")));QVBoxLayout* v12Layout = new QVBoxLayout;v12Layout->addWidget(aviFileNameLineEdit);v12Layout->addWidget(aviFilePathLineEdit);QVBoxLayout* v13Layout = new QVBoxLayout;v13Layout->addWidget(new QLabel(QStringLiteral(".avi")));v13Layout->addWidget(selectPathButton);QHBoxLayout* h11Layout  =new QHBoxLayout;h11Layout->addLayout(v11Layout);h11Layout->addLayout(v12Layout);h11Layout->addLayout(v13Layout);QHBoxLayout* h12Layout = new QHBoxLayout;QPushButton* okButton  =new QPushButton(QStringLiteral("确定"));QPushButton* cancelButton = new QPushButton(QStringLiteral("取消"));connect(okButton,SIGNAL(clicked()),dialog,SLOT(accept()));connect(cancelButton,SIGNAL(clicked()),dialog,SLOT(reject()));h12Layout->addStretch();h12Layout->addWidget(okButton);h12Layout->addWidget(cancelButton);h12Layout->addSpacing(10);QVBoxLayout* v21Layout = new QVBoxLayout;v21Layout->addLayout(h11Layout);v21Layout->addLayout(h12Layout);v21Layout->addStretch();dialog->setLayout(v21Layout);}int ret = dialog->exec();if(ret ==QDialog::Accepted ){qDebug()<<"Qdialog accepted" <<ret;}else{qDebug()<<"operate " <<ret;}// 根据widget内容来导出}



bool video::exportSrcSegment( string fileName ){if(!aviLocation(m_playIndex)){return false;}cv::VideoWriter  videoWriter;videoWriter.open(fileName,CV_FOURCC('D', 'I', 'V', 'X'),25.0,cv::Size(m_width,m_height),true);if (!videoWriter.isOpened()){return false;}Mat frame;for (int i=0;i< m_eventObj[m_playIndex].m_BlobList.size();i++){m_capture >> frame;videoWriter.write(frame);}videoWriter.release();return true;}




0 0
原创粉丝点击