Пример #1
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    // 创建文件系统模型
    QFileSystemModel model;
    // 指定要监视的目录
    model.setRootPath(QDir::currentPath());

    // 创建树型视图
    QTreeView tree;
    // 为视图指定模型
    tree.setModel(&model);
    // 指定根索引
    tree.setRootIndex(model.index(QDir::currentPath()));

    // 创建列表视图
    QListView list;
    list.setModel(&model);
    list.setRootIndex(model.index(QDir::currentPath()));

    tree.show();
    list.show();

    return app.exec();
}
Пример #2
0
//! [0] //! [1]
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QSplitter *splitter = new QSplitter;

//! [2] //! [3]
    QDirModel *model = new QDirModel;
//! [0] //! [2] //! [4] //! [5]
    QTreeView *tree = new QTreeView(splitter);
//! [3] //! [6]
    tree->setModel(model);
//! [4] //! [6] //! [7]
    tree->setRootIndex(model->index(QDir::currentPath()));
//! [7]

    QListView *list = new QListView(splitter);
    list->setModel(model);
    list->setRootIndex(model->index(QDir::currentPath()));

//! [5]
    QItemSelectionModel *selection = new QItemSelectionModel(model);
    tree->setSelectionModel(selection);
    list->setSelectionModel(selection);

//! [8]
    splitter->setWindowTitle("Two views onto the same directory model");
    splitter->show();
    return app.exec();
}
Пример #3
0
Rozmowa::Rozmowa(QWidget *parent, const QModelIndex& index, Model* mod ) :
    QDialog(parent),
    ui(new Ui::Rozmowa)
{
    ui->setupUi(this);
    message = this->findChild<QPlainTextEdit*>("wiadomosc");//message qplaintext wyslanie
    message->insertPlainText("");
    message->clear();
    QPushButton* send = this->findChild<QPushButton*>("send");
    model = mod;

    QModelIndex ind = model->index( index.row(), 0, QModelIndex() );
    //((MainWindow*)this->parent())->logged_user.numer;
    QVariant value = model->data( ind, Qt::DisplayRole).toString();
    QString title = value.toString();
    ind = model->index( index.row(), 2 );
    char numer[9];
    itoa(((MainWindow*)this->parent())->logged_user.numer,numer,10);
    title += " - (";
    //title += ind.data().toString();
    title += " moj numer: ";
    title += numer;
    title += ")";

    setWindowTitle(title);

    QListView* rozmowa = this->findChild<QListView*>("rozmowa");
    rozmowa->setModel(model);
    rozmowa->setRootIndex(index);

    connect(send, SIGNAL(clicked()), ((MainWindow*)this->parent())->socket, SLOT(send_text_message()));
    connect(this->model, SIGNAL(syg_rozm(int)),this,SLOT(syg_rozm_slot(int)));
}
Пример #4
0
void MainWindow::buildFileBrowser()
{
    QString rootPath = qgetenv("HOME");
    this->drivesModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);

    QTreeView *treeView = this->treeView = new QTreeView(this->ui->dockDir);
    treeView->setModel(this->drivesModel);
    treeView->setRootIndex(this->drivesModel->setRootPath(rootPath + "/../"));
    treeView->hideColumn(1);
    treeView->hideColumn(2);
    treeView->hideColumn(3);
    treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    treeView->setDragEnabled(true);
    treeView->setDragDropMode(QAbstractItemView::DragOnly);
    this->ui->dockDir->setWidget(treeView);

    this->filesModel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    QListView *listView = this->listView = new QListView(this->ui->dockFile);
    listView->setModel(this->filesModel);
    listView->setRootIndex(this->filesModel->setRootPath(rootPath));
    listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    listView->setDragEnabled(true);
    listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
    this->ui->dockFile->setWidget(listView);

    listView->show();
    treeView->show();
}
Пример #5
0
void Window::exempleDirModel()
{
    QVBoxLayout* layout = new QVBoxLayout;

    QDirModel* modele = new QDirModel;
    QTreeView* treeView = new QTreeView;
    QListView* listView = new QListView;

    treeView->setModel(modele);
    listView->setModel(modele);

    treeView->setRootIndex(modele->index("C:/MinGW"));
    listView->setRootIndex(modele->index("C:"));
    layout->addWidget(treeView);

    setCentralWidget(treeView);
}
Пример #6
0
void Test_FileSystem_MVC()
{
	QSplitter* splitter = new QSplitter;//two widget
	QFileSystemModel* model = new QFileSystemModel;
	QTreeView* tree = new QTreeView(splitter);//left tree view
	QListView* list = new QListView(splitter);//right list view

	splitter->setWindowTitle("Two vies onto the same file system model");

	model->setRootPath(QDir::currentPath());
	tree->setModel(model);//set model for view
	tree->setRootIndex(model->index(QDir::currentPath()));

	list->setModel(model);
	list->setRootIndex(model->index(QDir::currentPath()));

	list->setSelectionModel(tree->selectionModel());
	splitter->show();

}
Пример #7
0
int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QSplitter splitter;

    QTreeView *tree = new QTreeView(&splitter);
    QListView *list = new QListView(&splitter);

    QFileSystemModel *model = new QFileSystemModel(&app);
    model->setRootPath(QDir::root().path());

    tree->setModel(model);
    list->setModel(model);

    list->setRootIndex(model->index("."));

    splitter.show();

    return app.exec();
}