QML使用C++定义枚举
立即下载
资源介绍:
QML使用C++定义枚举样例代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
initQmlWidget();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initQmlWidget()
{
m_pQmlView = new QQuickView();
m_pQmlView->setSource(QUrl("qrc:/EnumTest.qml"));
m_pQmlPanel = (QQuickWidget*)QWidget::createWindowContainer(m_pQmlView,this);
m_pContext = m_pQmlView->rootContext();
m_pQmlPanel->show();
}
void MainWindow::resizeEvent(QResizeEvent* e)
{
m_pQmlPanel->setGeometry(rect());
m_pContext->setContextProperty("appMainWindow", this);
}
void MainWindow::callFun(FunType funType)
{
QString strMsg = tr("当前颜色");
switch(funType){
case FunType::RED:
strMsg += tr("红色");
break;
case FunType::YELLOW:
strMsg += tr("黄色");
break;
case FunType::BLUE:
strMsg += tr("蓝色");
break;
default:
strMsg += QStringLiteral("无选项");
}
QMessageBox::information(this,"info",strMsg);
}