16 Ocak 2017 Pazartesi

QT NOTES2

#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    QString sPath ="/";
    dirmodel = new QFileSystemModel(this);
    dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
    dirmodel->setRootPath(sPath);
    ui->treeView->setModel(dirmodel);
    filemodel = new QFileSystemModel(this);

    filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    ui->listView->setModel(filemodel);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_treeView_clicked(const QModelIndex &index)
{
    QString sPath = dirmodel->fileInfo(index).absoluteFilePath();
    ui->listView->setRootIndex(filemodel->setRootPath(sPath));
}
Share:

QT NOTES1

#include "dialog.h"
#include "ui_dialog.h"
#include
#include
#include
#include
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    model = new QDirModel(this);
    model->setReadOnly(false);
    ui->treeView->setModel(model);
    QModelIndex index = model->index("/");
    ui->treeView->expand(index);
    ui->treeView->scrollTo(index);
    ui->treeView->setCurrentIndex(index);
    ui->treeView->resizeColumnToContents(0);

}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::on_pushButton_clicked()
{
    QModelIndex index = ui->treeView->currentIndex();
    if(!index.isValid()) return;
    QString name = QInputDialog::getText(this,"Makedir A file ","Name");
    if(name.isEmpty()) return;
    model->mkdir(index,name);
}

void Dialog::on_pushButton_2_clicked()
{

}
Share: