用QComboBox实现tree状结构(QComboBox居然欧setView函数)

时间:2015-12-22 21:08:08   收藏:0   阅读:483

实现的效果图如下: 
技术分享

#include "mainwindow.h" 
#include <QApplication> 
#include <QTreeView> 
#include <QFileSystemModel> 
#include <QComboBox> 
#include <QDir>

int main(int argc, char *argv[]) 
{

QApplication a(argc, argv);
MainWindow w;
// 创建文件系统模型
QFileSystemModel *model = new QFileSystemModel(&w);
// 指定要监视的目录
model->setRootPath(QDir::currentPath());
QTreeView *tree = new QTreeView(&w);
tree->setModel(model);
tree->setRootIndex(model->index(QDir::currentPath()));
QComboBox *b = new QComboBox(&w);
b->resize(400, 20);
b->setView(tree);
b->setModel(model);
b->show();

w.show();

return a.exec();

} 
///////完

http://blog.csdn.net/u011915578/article/details/47783577

原文:http://www.cnblogs.com/findumars/p/5068071.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!