Browse Source

basic navigation

master
hex 5 years ago
parent
commit
6e4e17d9bb
  1. 19
      include/window.h
  2. 21
      src/window.cpp

19
include/window.h

@ -1,17 +1,22 @@ @@ -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;
};

21
src/window.cpp

@ -3,18 +3,31 @@ @@ -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