http://doc.qt.io/qt-4.8/qt-itemviews-dirview-example.html
위의 예제를 이용하면 QFileSystemModel을 이용해서 간단하게 Dir view를 만들수 있다.
그러나 이미지를 봐서 알겠지만 Dir만 표시되지 않고 부가적인 것까지 표시가 된다.
그래서 간단하게 수정을 했다.
class DirSystemModel : public QFileSystemModel
{
Q_OBJECT
public:
DirSystemModel(QObject *parent) : QFileSystemModel(parent)
{
this->setRootPath("");
this->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
this->sort(0, Qt::SortOrder::AscendingOrder);
}
//~DirSystemModel();
int columnCount(const QModelIndex & /* parent */) const {return 1;}
QVariant data(const QModelIndex &index, int role) const {
return QFileSystemModel::data(index, role);;
}
};
아래에 있는 예제 소스에서 QFileSystemModel 대신 DirSystemModel을 사용하면 된다.
#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); DirSystemModel model; model.setRootPath(""); QTreeView tree; tree.setModel(&model); // Demonstrating look and feel features tree.setAnimated(false); tree.setIndentation(20); //tree.setSortingEnabled(true); tree.setWindowTitle(QObject::tr("Dir View")); #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) tree.showMaximized(); #else tree.resize(640, 480); tree.show(); #endif return app.exec(); }
LIST
'QT and Symbian' 카테고리의 다른 글
| Visual Studio에서 QtWinExtras 사용을 위한 세팅방법 (0) | 2015.06.17 |
|---|---|
| C++ Qt 06 - layouts, tabs and buddies (0) | 2015.05.29 |
| SLOT에서 SIGNAL Widget 확인하는 방법 (0) | 2015.05.28 |
| QImage Format 중 QImage::Format_Mono 처리 방식 (0) | 2015.01.30 |
| QT에서 WinAPI SetFilePointer() 함수 대체 방법 (0) | 2014.12.05 |