zoukankan      html  css  js  c++  java
  • QDirModel

    #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);
        }
    }
    

      

  • 相关阅读:
    linux 下怎么看postgresql安装到哪个目录了?
    sqlserver 存储image 语句
    thinkphp5.1 配置使用
    百度车牌识别demo
    elastticsearch 安装
    InDB开发
    John爆破密码
    域传送漏洞
    新远程下载方式(IME)
    SSH端口转发
  • 原文地址:https://www.cnblogs.com/my-cat/p/6197585.html
Copyright © 2011-2022 走看看