vs+qt-vs-addin-1.1.11-opensource开发环境下:如何添加qdialog,并可以用设计师设计
2015-05-18 14:42
459 查看
我们现在的开发环境是VS2010+QT插件的方式,这个时候我想在某个工程里面添加一个dialog对话框,分三步走:
第一步:用QT Designer 新建一个.ui文件,命名为geostralayerNameChoice.ui,然后完成编辑。
第一:新增加一个dialog类,继承自 QDialog,比如class CGeoStraLayerNameChoiceDialog :public QDialog。
在类的头文件中添加如下代码:
/**
* @file GeoStraLayerNameChoiceDialog.h
* @brief
* @date 2015-5-22
* @author: hudongfang
*/
#ifndef PAI_FRAME_CGEOSTRALAYERNAMECHOICEDIALOG_H
#define PAI_FRAME_CGEOSTRALAYERNAMECHOICEDIALOG_H
#pragma warning( push ,0 )
#include <QDialog>
#include "OSGFramework.h"
#include "GeologicalStratificationTree.h"
#include "GeologicalStratificatonObject.h"
#include "DialogFactory.h"
#pragma warning( pop )
namespace Ui
{
class GeoStraLayerNameChoiceDialog;
}
using namespace pai::datamodel;
BEGIN_OSGGRAPHICS_NAMESPACE
class CGeoStraLayerNameChoiceDialog :public QDialog,public CDialogFactory
{
Q_OBJECT
public:
CGeoStraLayerNameChoiceDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
~CGeoStraLayerNameChoiceDialog(void);
private slots:
void slotOK();
void slotCancel();
//void slotEdit();
virtual QString GetGuid();
private:
Ui::GeoStraLayerNameChoiceDialog* m_pUI;
//层位级别树
CGeologicalStratificationTree* m_pDataTree_GeoStra;
};
END_OSGGRAPHICS_NAMESPACE
//using namespace pai::graphics;
#endif
在源文件的构造函数中添加如下代码:
#include <QHBoxLayout>
#include "GeoStraLayerNameChoiceDialog.h"
#include "ui_GeoStraLayerNameChoice.h"
#include "GeologicalStratificationRoot.h"
#include "OSGDataModel.h"
#include "GeologicalStratificationDialog.h"
#include "ObjProject.h"
#include "BaseObject.h"
using namespace pai::datamodel;
BEGIN_OSGGRAPHICS_NAMESPACE
CGeoStraLayerNameChoiceDialog::CGeoStraLayerNameChoiceDialog(QWidget *parent, Qt::WFlags flags)
:QDialog(parent,flags),
m_pDataTree_GeoStra(NULL)
{
m_pUI = new Ui::GeoStraLayerNameChoiceDialog();
m_pUI->setupUi(this);
//地质分层命名树
m_pDataTree_GeoStra = new CGeologicalStratificationTree(this);
m_pDataTree_GeoStra->InitTreeType(eTree_GeologicalStratification);
//SetGeoStraTree(m_pDataTree_Geological);
QHBoxLayout * hLayout = new QHBoxLayout();
hLayout->addWidget(m_pDataTree_GeoStra);
hLayout->setContentsMargins(10,10,10,10);
m_pUI->groupBox_layerName->setLayout(hLayout);
if( GetProject() )
{
m_pDataTree_GeoStra->SetRootObject(GetProject()->GetGeologicalStratificationRoot(true));
PaiObject *pObject = GetProject()->GetGeologicalStratificationRoot(true);
QList<PaiObject *> listChild;
pObject->GetChildren(listChild);
PaiObject::m_eventAgent.OnObjectAddChildren( pObject,listChild);
}
QObject::connect(m_pUI->pushButton_OK, SIGNAL(clicked()), this, SLOT(slotOK()) );
QObject::connect(m_pUI->pushButton_CANCEL, SIGNAL(clicked()), this, SLOT(slotCancel()) );
//QObject::connect(m_pUI->pushButton_Edit, SIGNAL(clicked()), this, SLOT(slotEdit()) );
}
CGeoStraLayerNameChoiceDialog::~CGeoStraLayerNameChoiceDialog(void)
{
delete m_pUI;
m_pUI = NULL;
delete m_pDataTree_GeoStra;
m_pDataTree_GeoStra = NULL;
}
void CGeoStraLayerNameChoiceDialog::slotOK()
{
QTreeWidgetItem * pTreeItem = m_pDataTree_GeoStra->currentItem();
QString strName = pTreeItem->text(0);
this->setWindowTitle(strName);
QDialog::accept();//注意此处如何调用基类的确定代码
}
void CGeoStraLayerNameChoiceDialog::slotCancel()
{
QDialog::reject();//注意此处如何调用积累的取消代码(关闭对话框)
}
附:
CSelectDlg dlg;
int res = dlg.exec();
if (res == QDialog::Accepted) isOilLayer = true;
if (res == QDialog::Rejected) isOilLayer = false;
//注意 QDialog::accept()、QDialog::reject()、 QDialog::Accepted、 QDialog::Rejected
第一步:用QT Designer 新建一个.ui文件,命名为geostralayerNameChoice.ui,然后完成编辑。
第一:新增加一个dialog类,继承自 QDialog,比如class CGeoStraLayerNameChoiceDialog :public QDialog。
在类的头文件中添加如下代码:
/**
* @file GeoStraLayerNameChoiceDialog.h
* @brief
* @date 2015-5-22
* @author: hudongfang
*/
#ifndef PAI_FRAME_CGEOSTRALAYERNAMECHOICEDIALOG_H
#define PAI_FRAME_CGEOSTRALAYERNAMECHOICEDIALOG_H
#pragma warning( push ,0 )
#include <QDialog>
#include "OSGFramework.h"
#include "GeologicalStratificationTree.h"
#include "GeologicalStratificatonObject.h"
#include "DialogFactory.h"
#pragma warning( pop )
namespace Ui
{
class GeoStraLayerNameChoiceDialog;
}
using namespace pai::datamodel;
BEGIN_OSGGRAPHICS_NAMESPACE
class CGeoStraLayerNameChoiceDialog :public QDialog,public CDialogFactory
{
Q_OBJECT
public:
CGeoStraLayerNameChoiceDialog(QWidget *parent = 0, Qt::WFlags flags = 0);
~CGeoStraLayerNameChoiceDialog(void);
private slots:
void slotOK();
void slotCancel();
//void slotEdit();
virtual QString GetGuid();
private:
Ui::GeoStraLayerNameChoiceDialog* m_pUI;
//层位级别树
CGeologicalStratificationTree* m_pDataTree_GeoStra;
};
END_OSGGRAPHICS_NAMESPACE
//using namespace pai::graphics;
#endif
在源文件的构造函数中添加如下代码:
#include <QHBoxLayout>
#include "GeoStraLayerNameChoiceDialog.h"
#include "ui_GeoStraLayerNameChoice.h"
#include "GeologicalStratificationRoot.h"
#include "OSGDataModel.h"
#include "GeologicalStratificationDialog.h"
#include "ObjProject.h"
#include "BaseObject.h"
using namespace pai::datamodel;
BEGIN_OSGGRAPHICS_NAMESPACE
CGeoStraLayerNameChoiceDialog::CGeoStraLayerNameChoiceDialog(QWidget *parent, Qt::WFlags flags)
:QDialog(parent,flags),
m_pDataTree_GeoStra(NULL)
{
m_pUI = new Ui::GeoStraLayerNameChoiceDialog();
m_pUI->setupUi(this);
//地质分层命名树
m_pDataTree_GeoStra = new CGeologicalStratificationTree(this);
m_pDataTree_GeoStra->InitTreeType(eTree_GeologicalStratification);
//SetGeoStraTree(m_pDataTree_Geological);
QHBoxLayout * hLayout = new QHBoxLayout();
hLayout->addWidget(m_pDataTree_GeoStra);
hLayout->setContentsMargins(10,10,10,10);
m_pUI->groupBox_layerName->setLayout(hLayout);
if( GetProject() )
{
m_pDataTree_GeoStra->SetRootObject(GetProject()->GetGeologicalStratificationRoot(true));
PaiObject *pObject = GetProject()->GetGeologicalStratificationRoot(true);
QList<PaiObject *> listChild;
pObject->GetChildren(listChild);
PaiObject::m_eventAgent.OnObjectAddChildren( pObject,listChild);
}
QObject::connect(m_pUI->pushButton_OK, SIGNAL(clicked()), this, SLOT(slotOK()) );
QObject::connect(m_pUI->pushButton_CANCEL, SIGNAL(clicked()), this, SLOT(slotCancel()) );
//QObject::connect(m_pUI->pushButton_Edit, SIGNAL(clicked()), this, SLOT(slotEdit()) );
}
CGeoStraLayerNameChoiceDialog::~CGeoStraLayerNameChoiceDialog(void)
{
delete m_pUI;
m_pUI = NULL;
delete m_pDataTree_GeoStra;
m_pDataTree_GeoStra = NULL;
}
void CGeoStraLayerNameChoiceDialog::slotOK()
{
QTreeWidgetItem * pTreeItem = m_pDataTree_GeoStra->currentItem();
QString strName = pTreeItem->text(0);
this->setWindowTitle(strName);
QDialog::accept();//注意此处如何调用基类的确定代码
}
void CGeoStraLayerNameChoiceDialog::slotCancel()
{
QDialog::reject();//注意此处如何调用积累的取消代码(关闭对话框)
}
附:
CSelectDlg dlg;
int res = dlg.exec();
if (res == QDialog::Accepted) isOilLayer = true;
if (res == QDialog::Rejected) isOilLayer = false;
//注意 QDialog::accept()、QDialog::reject()、 QDialog::Accepted、 QDialog::Rejected
相关文章推荐
- VS2010 + QT5.2+ QT-VS-Addin1.2.2开发环境配置
- qt-vs-addin:Qt4和Qt5之VS插件如何共存与使用
- QT4.8.5+qt-vs-addin-1.1.11+VS2010安装配置和QT工程的新建和加载
- PyQt中如何结合Qt设计师进行开发
- windows8 下基于vs2013开发环境CGAL配置(cmake,cgal,qt.boost,qglviewer)教程
- 如何利用VS2010进行QT开发的环境配置(win10+VS2010+QT4.8.6)
- QT4.8.5+qt-vs-addin-1.1.11+VS2010安装配置和QT工程的新建和加载
- qt 4.6.2 vs 2005 + QCreator 开发环境配置(有注册码)
- 【转】qt-vs-addin:Qt4和Qt5之VS插件如何共存与使用
- 如何利用QT设计师设计的ui生成相应头文件
- VS2008环境QT开发(一)环境搭建
- VS2013 平台下搭建 QT5.3 开发环境
- 如何在Windows平台使用VS搭建C++/Lua的开发环境
- 如何在Windows平台使用VS搭建C++/Lua的开发环境
- QT4.8.5+qt-vs-addin-1.1.11+VS2010安装配置和QT工程的新建和加载
- 如何配置一个绿色化的 Qt for Windows 开发环境
- s3c2410上搭建QT/Embedded4.8.5开发环境(四)--安装intel-x86 X11平台qt库qt-everywhere-opensource-src-4.8.5
- s3c2410上搭建QT/Embedded4.8.5开发环境(二)--安装arm平台qt库qt-everywhere-opensource-src-4.8.5
- vs2012 手动编译Qt5开发环境
- s3c2410上搭建QT/Embedded4.8.5开发环境(三)--安装intel-x86嵌入式平台(基于qvfb)的qt库qt-everywhere-opensource-src-4.8.5