vs+qt-vs-addin-1.1.11-opensource开发环境下:如何添加qdialog,并可以用设计师设计

我们现在的开发环境是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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值