Hi again,
app.cpp
#include "app.hpp"
{
m_ui.setupUi(this);
model = new QFileSystemModel(this);
model
->setRootPath
(QDir::currentPath());
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(model);
proxyModel
->mapFromSource
(model
->index
(QDir::currentPath()));
m_ui.listView->setModel(proxyModel);
m_ui.
listView->setRootIndex
(proxyModel
->mapFromSource
(model
->index
(QDir::currentPath())));
connect(m_ui.
lineEdit,
SIGNAL(textChanged
(QString)),
this,
SLOT(filter
(QString)));
}
void App
::filter(QString pattern_filter
) {
proxyModel->setFilterFixedString(pattern_filter);
}
#include "app.hpp"
App::App(QWidget * p_parent): QMainWindow(p_parent)
{
m_ui.setupUi(this);
model = new QFileSystemModel(this);
model->setRootPath(QDir::currentPath());
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(model);
proxyModel->mapFromSource(model->index(QDir::currentPath()));
m_ui.listView->setModel(proxyModel);
m_ui.listView->setRootIndex(proxyModel->mapFromSource(model->index(QDir::currentPath())));
connect(m_ui.lineEdit, SIGNAL(textChanged(QString)), this, SLOT(filter(QString)));
}
void App::filter(QString pattern_filter)
{
proxyModel->setFilterFixedString(pattern_filter);
}
To copy to clipboard, switch view to plain text mode
app.hpp:
#ifndef _HPP_APP
#define _HPP_APP
#include <QFileSystemModel>
#include <QMainWindow>
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
#include <QDir>
#include <QTextStream>
#include "ui_app.h"
{
Q_OBJECT
public:
public slots:
private:
Ui::MainWindow m_ui;
QFileSystemModel *model;
};
#endif
#ifndef _HPP_APP
#define _HPP_APP
#include <QFileSystemModel>
#include <QMainWindow>
#include <QSortFilterProxyModel>
#include <QFileSystemModel>
#include <QDir>
#include <QTextStream>
#include "ui_app.h"
class App : public QMainWindow
{
Q_OBJECT
public:
App(QWidget * p_parent = 0);
public slots:
void filter(QString );
private:
Ui::MainWindow m_ui;
QSortFilterProxyModel *proxyModel;
QFileSystemModel *model;
};
#endif
To copy to clipboard, switch view to plain text mode
ui_app.h:
/********************************************************************************
** Form generated from reading UI file 'app.ui'
**
** Created: Sat Aug 7 21:35:40 2010
** by: Qt User Interface Compiler version 4.6.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_APP_H
#define UI_APP_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QListView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
{
if (MainWindow->objectName().isEmpty())
MainWindow
->setObjectName
(QString::fromUtf8("MainWindow"));
MainWindow->resize(686, 402);
centralwidget
= new QWidget(MainWindow
);
centralwidget
->setObjectName
(QString::fromUtf8("centralwidget"));
verticalLayout
->setObjectName
(QString::fromUtf8("verticalLayout"));
lineEdit
->setObjectName
(QString::fromUtf8("lineEdit"));
verticalLayout->addWidget(lineEdit);
listView
->setObjectName
(QString::fromUtf8("listView"));
verticalLayout->addWidget(listView);
MainWindow->setCentralWidget(centralwidget);
menubar
->setObjectName
(QString::fromUtf8("menubar"));
menubar
->setGeometry
(QRect(0,
0,
686,
25));
MainWindow->setMenuBar(menubar);
statusbar
->setObjectName
(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
toolBar
->setObjectName
(QString::fromUtf8("toolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, toolBar);
retranslateUi(MainWindow);
} // setupUi
{
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_APP_H
/********************************************************************************
** Form generated from reading UI file 'app.ui'
**
** Created: Sat Aug 7 21:35:40 2010
** by: Qt User Interface Compiler version 4.6.2
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_APP_H
#define UI_APP_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
#include <QtGui/QListView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralwidget;
QVBoxLayout *verticalLayout;
QLineEdit *lineEdit;
QListView *listView;
QMenuBar *menubar;
QStatusBar *statusbar;
QToolBar *toolBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(686, 402);
centralwidget = new QWidget(MainWindow);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
verticalLayout = new QVBoxLayout(centralwidget);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
lineEdit = new QLineEdit(centralwidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
verticalLayout->addWidget(lineEdit);
listView = new QListView(centralwidget);
listView->setObjectName(QString::fromUtf8("listView"));
verticalLayout->addWidget(listView);
MainWindow->setCentralWidget(centralwidget);
menubar = new QMenuBar(MainWindow);
menubar->setObjectName(QString::fromUtf8("menubar"));
menubar->setGeometry(QRect(0, 0, 686, 25));
MainWindow->setMenuBar(menubar);
statusbar = new QStatusBar(MainWindow);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
toolBar = new QToolBar(MainWindow);
toolBar->setObjectName(QString::fromUtf8("toolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, toolBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
toolBar->setWindowTitle(QApplication::translate("MainWindow", "toolBar", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_APP_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "app.hpp"
int main(int argc, char ** argv)
{
App myapp;
myapp.show();
return app.exec();
}
#include <QtGui/QApplication>
#include "app.hpp"
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
App myapp;
myapp.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks