#include "dialog.h"
#include "ui_dialog.h"
#include<QInputDialog> Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
model = new QDirModel(this);
model->setReadOnly(false);
model->setSorting(QDir::DirsFirst|QDir::IgnoreCase|QDir::Name); ui->treeView->setModel(model);
QModelIndex index=model->index("E:/"); ui->treeView->expand(index);
ui->treeView->scrollTo(index);
ui->treeView->setCurrentIndex(index);
ui->treeView->resizeColumnToContents(0);
} Dialog::~Dialog()
{
delete ui;
} void Dialog::on_pushButton_2_clicked()
{
//make
QModelIndex index = ui->treeView->currentIndex();
if(!index.isValid()) return; QString name = QInputDialog::getText(this, "name","Enter a name:");
if(name.isEmpty()) return;
model->mkdir(index,name);
} void Dialog::on_pushButton_clicked()
{
//delete
QModelIndex index = ui->treeView->currentIndex();
if(!index.isValid()) return; if(model->fileInfo(index).isDir())
{
//dir
model->rmdir(index);
}
else
{
//file
model->remove(index);
}
}

  

QDirModel的更多相关文章

  1. (三)使用预定义模型QDirModel的例子

    使用预定义模型QDirModel的例子 Main.cpp #include <QApplication> #include "directoryviewer.h" in ...

  2. QT目录模型QDirModel的使用(一个model同时连接tree,list,table)

    3#include <QApplication>#include <QAbstractItemModel>#include <QAbstractItemView># ...

  3. Qt QFileSystemModel QDirModel 示例代码, 使用方法

    1.  QFileSystemModel 查看,添加 和 删除目录 2. 实现代码 dialog.h #ifndef DIALOG_H #define DIALOG_H #include <QD ...

  4. Qt Model/View(官方翻译,图文并茂)

    http://doc.trolltech.com/main-snapshot/model-view-programming.html 介绍 Qt 4推出了一组新的item view类,它们使用mode ...

  5. (转)Qt Model/View 学习笔记 (三)——Model类

    Model类 基本概念 在model/view构架中,model为view和delegates使用数据提供了标准接口.在Qt中,标准接口QAbstractItemModel类中被定义.不管数据在底层以 ...

  6. (转)Qt Model/View 学习笔记 (二)——Qt Model/View模式举例

    Qt Model/View模式举例 Qt提供了两个标准的models:QStandardItemModel和QDirModel.QStandardItemModel是一个多用途的model,可用于表示 ...

  7. (转)Qt Model/View 学习笔记 (一)——Qt Model/View模式简介

    Qt Model/View模式简介 Qt 4推出了一组新的item view类,它们使用model/view结构来管理数据与表示层的关系.这种结构带来的 功能上的分离给了开发人员更大的弹性来定制数据项 ...

  8. qt 总结

    Qt中的每个类,都有一个对应的同名头文件,其中包含其类定义.例如要使用QApplication类,则需要在程序中添加" #include <QApplication>" ...

  9. 《Qt编程的艺术》——8.2.1 在Designer中使用View类

    不幸的是,QDirModel有一个严重的限制:因为view不响应鼠标操作,我们不得不自己建立这些功能.除此之外,每个view中,用户都一次只能选择一个元素.如果你想要允许同时选择多个项目,你也必须自己 ...

随机推荐

  1. Win10 Build9926 更新问题解决

    将Dns 改为 4.2.2.2 备用 4.2.2.1

  2. seajs hello world

    http://localhost/seajs/index.html <!doctype html> <head> <title>Hello Seajs</ti ...

  3. iOS文件类型判断

    最近在做的东西有下载zip,只是服务器发送过来的是二进制,需要根据二进制来判断是什么类型的文件,从而进行保存操作.起初很不理解,到后来发现可以通过二进制的前2位的ascii码来进行判断.如下: // ...

  4. python--基础学习(五)参数位置传递、关键字传递、包裹传递及解包裹

    python系列均基于python3.4环境 1.位置传递和关键字传递 代码示例 #位置传递 def fun(a,b,c): print("a: {0}, b: {1}, c: {2}&qu ...

  5. 行为型模式之Template Method模式

    模板方法模式(Template Method Pattern) 又叫模板模式,通过定义一个操作的算法骨架,而将一些步骤延迟到子类中,可以不改变一个算法的结构,却又可以重新定义概算法的某些特定步骤. 应 ...

  6. xml schema xmlns xmlns:xsi xsi:schemaLocation targetnamespace

    先上一段xml文档 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  7. iis 7.0 asp.net发布问题

    问题1: 配置错误:不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的………… 解决方案: 因为 IIS 7 采用了更安全的 web.config 管理机制,默认 ...

  8. You don't have permission to access /index.php on this server

    <Directory /> #AllowOverride none #Require all denied</Directory>

  9. XCode6 生成prefix.pch文件

    XCode6里, 新建工程默认是没有pch文件的,苹果取消pch文件这一点肯定有它的道理,刚开始很多人可能不适应,如果我们想使用pch文件,需要手动添加,添加步骤如下:(依旧直接上图)

  10. T-SQL Recipes之 Table Variables and Temporary Tables

    Problem 许多时候, 我们想要Table Variables在动态SQL中执行,但现实是很骨感的.比如这个示例: DECLARE @sql_command NVARCHAR(MAX); DECL ...