当前位置: 首页>>代码示例>>C++>>正文


C++ TreeModel::setXML方法代码示例

本文整理汇总了C++中TreeModel::setXML方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeModel::setXML方法的具体用法?C++ TreeModel::setXML怎么用?C++ TreeModel::setXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeModel的用法示例。


在下文中一共展示了TreeModel::setXML方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QWidget

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , m_height(30)
    , m_shadowSize(5)
    , m_menu(NULL)
{
    this->setWindowFlags(Qt::FramelessWindowHint | Qt::Window);
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowIcon(QIcon("./Resources/Images/icon.png"));

    m_comboBox = new QComboBox(this);
    QStringList strList;
    strList << QStringLiteral("样式一") << QStringLiteral("样式二") << QStringLiteral("样式三");
    for (int i = 0; i < strList.count(); ++i)
    {
        m_comboBox->addItem(strList.at(i));
    }
    m_comboBox->setFixedSize(100, 25);
    m_comboBox->setView(new QListView());

    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeStyle(int)));

    m_treeView = new QTreeView(this);
    ItemDelegate *delegate = new ItemDelegate(this);
    TreeModel *model = new TreeModel(this);

    model->setXML(Util::exePath() + "/Resources/ToolsConfig.xml");

    m_treeView->setHeaderHidden(true);
    m_treeView->setAnimated(true);
    m_treeView->setMouseTracking(true);
    m_treeView->setExpandsOnDoubleClick(true);
    m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    m_treeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    m_treeView->setModel(model);
    delegate->setView(m_treeView);
    m_treeView->setItemDelegate(delegate);

    connect(delegate, SIGNAL(expanded(const QModelIndex &)), this, SLOT(expanded(const QModelIndex &)));

    m_label = new QLabel(this);
    m_closeButton = new QPushButton(this);
    m_closeButton->setFixedSize(27, 22);
    m_closeButton->setObjectName("closeButton");
    m_closeButton->setToolTip(QStringLiteral("关闭"));

    m_label->setObjectName("titleLabel");
    m_label->setText(QStringLiteral("自定义TreeView"));

    QHBoxLayout *titleLayout = new QHBoxLayout();
    titleLayout->addWidget(m_label);
    titleLayout->addStretch();
    titleLayout->addWidget(m_closeButton);
    titleLayout->setSpacing(0);
    titleLayout->setContentsMargins(5, 0, 5, 0);

    QHBoxLayout *styleLayout = new QHBoxLayout();
    styleLayout->addWidget(m_comboBox);
    styleLayout->addStretch();
    styleLayout->setSpacing(0);
    styleLayout->setContentsMargins(20, 0, 0, 0);

    QHBoxLayout *centerLayout = new QHBoxLayout();
    centerLayout->addWidget(m_treeView);
    centerLayout->setSpacing(0);
    centerLayout->setContentsMargins(25, 0, 25, 25);

    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->addLayout(titleLayout);
    mainLayout->addLayout(styleLayout);
    mainLayout->addLayout(centerLayout);
    mainLayout->setSpacing(20);
    mainLayout->setContentsMargins(5, 3, 5, 7);

    this->setLayout(mainLayout);

    QDesktopWidget *pDesktop = QApplication::desktop();
    m_rect = pDesktop->availableGeometry();

    connect(m_treeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(treeViewCustomContextMenuRequested(QPoint)));
    connect(m_closeButton, SIGNAL(clicked()), qApp, SLOT(quit()));

    m_treeView->expandAll();
    this->changeStyle(0);
}
开发者ID:GLDsuh-a,项目名称:qt-1,代码行数:86,代码来源:mainwindow.cpp


注:本文中的TreeModel::setXML方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。