Browse Source

basic navigation

master
hex 4 years ago
parent
commit
6e4e17d9bb
2 changed files with 29 additions and 11 deletions
  1. 12
    7
      include/window.h
  2. 17
    4
      src/window.cpp

+ 12
- 7
include/window.h View File

@@ -1,17 +1,22 @@
#pragma once

#include <QWidget>
#include <QModelIndex>


class QPushButton;
class QListView;
class QStandardItemModel;
class QFileSystemModel;

class Window : public QWidget {
public:
explicit Window(QWidget *parent = 0);
public:
explicit Window(QWidget *parent = 0);

private:
QPushButton *mButton;
QListView *mListView;
QStandardItemModel *mModel;
public slots:
void changeIndex(const QModelIndex& index);
private:
QPushButton *mButton;
QListView *mListView;
QFileSystemModel *mModel;
};

+ 17
- 4
src/window.cpp View File

@@ -3,18 +3,31 @@
#include <QPushButton>
#include <QListView>
#include <QStandardItemModel>
#include <QFileSystemModel>
#include <QString>
#include <QHBoxLayout>

Window::Window(QWidget *parent) :
QWidget(parent)
{
QHBoxLayout* splitter = new QHBoxLayout(this);
mListView = new QListView(this);
mButton = new QPushButton("add", this);
splitter->addWidget(mListView);
this->setLayout(splitter);
//mButton = new QPushButton("add", this);

mModel = new QStandardItemModel();
mModel = new QFileSystemModel();
mListView->setModel(mModel);

for (int i = 1; i <= 10; ++i) {
mModel->appendRow(new QStandardItem(QString(i)));
mModel->setRootPath("/home/user/");
mListView->setRootIndex(mModel->index("/home/user/"));

QObject::connect(mListView, &QListView::doubleClicked,
this, &Window::changeIndex);
}

void Window::changeIndex(const QModelIndex& index) {
if (mModel->isDir(index)) {
mListView->setRootIndex(index);
}
}

Loading…
Cancel
Save