qfilesystemmodel

QFileSystemModel and QTreeView showing dirs only. How to hide expansion marks against the empty dirs?

天涯浪子 提交于 2019-12-24 15:57:39
问题 I'm building somewhat like standard file explorer - left pane is for folders tree, and the right one to display files within selected folder. QTreeView with QFileSystemModel is used to display folders. Model's filter is set to QDir::Dirs | QDir::NoDotAndDotDot to list dirs only, no files. I want to display expansion marks only against the folders with subfolders, i. e. if some dir is empty or contains only files, it shouldn't be expandable. But instead, tree view keeps expansion marks against

Fails to display mp3 files in TreeView in Qt

烂漫一生 提交于 2019-12-23 06:07:53
问题 Alright I seem to have come across a situation where I need to traverse my directories and search for only .mp3 and .mpeg files. Once searched, I want to display them in my tree view. Basically I have 2 tree views in my app, one displays the system directories and other should display only .mp3 and .mpeg files. Here is the code // Gets called when application starts void DetailView::onCamStartup() { m_SystemModel = new QFileSystemModel(this); m_SystemListViewModel = new QFileSystemModel(this)

PyQt: QFileSystemModel checkbox filter

霸气de小男生 提交于 2019-12-22 08:10:28
问题 I am trying to make a utility using python/pyqt to create a *.tar archive from a QFileSystemModel (including only those items that are checked). Now I want control of QFileSystemModel checkboxes to filter with fileName / fileType / fileSize. How can i check/uncheck QFileSystemModel checkboxes outside of the class with a wildcard search on fileName / fileType / fileSize? class CheckableDirModel(QtGui.QFileSystemModel): def __init__(self, parent=None): QtGui.QFileSystemModel.__init__(self, None

QFileSystemModel not updating when files change

只谈情不闲聊 提交于 2019-12-13 19:30:50
问题 I'm having trouble with QFileSystemModel not showing changes to files. When a file is first created it immediately shows up. But when the file itself changes, the size and timestamp don't update. I've made multiple attempts at trying to force the model to update with no real success. The best I've achieved is to completely replace the model. Although that results in this error: QSortFilterProxyModel: index from wrong model passed to mapToSource The test code below creates a table view of an

How to find an item in a QTreeView?

跟風遠走 提交于 2019-12-13 06:12:12
问题 I understand that QTreeWidget has methods for finding an item, but since I want to use a QFileSystemModel , then I'm limited to QTreeView . However, I'd still like to be able to return all items from a QTreeView and place them into a list. I had thought that I could go through and grab all indexes from the QTreeView , but I'm not sure how to do that. Maybe something like: QList<QModelIndex &> treeList; foreach(QModelIndex &index, ui->tv_list) { treeList.append(index); } but I know this isn't

QFileSystemModel and QTreeView

青春壹個敷衍的年華 提交于 2019-12-13 02:46:39
问题 I show a QFileSystemModel through a QTreeView. Whenever the user clicks on a directory (expanded or not expanded) I want to get a list of the files inside this directory. void MyModel::selectionChanged(const QItemSelection& selected,const QItemSelection& deselected) { for (auto const & it : selected.indexes()) { for (int i=0;i<rowCount(it);i++) { auto child = it.child(i, it.column()); qDebug() << fileName(child); } } } The problem with the above code is that this only seems to work once that

Using QFileSystemModel to display only one directory

核能气质少年 提交于 2019-12-12 19:24:48
问题 Is it possible to use QFileSystemModel to list only one directory contents instead of all drives in my computer (in Windows)? 回答1: That would be a function of your view, not your model: http://doc.trolltech.com/latest/qabstractitemview.html#setRootIndex Update : No more Trolltech links, the updated link is QAbstractItemView Class 来源: https://stackoverflow.com/questions/4436017/using-qfilesystemmodel-to-display-only-one-directory

How to add a custom role to QFileSystemModel

眉间皱痕 提交于 2019-12-12 19:18:18
问题 I would like to add a custom role to a QFileSystemModel (probably to a derived model). I want to use this role to save the check state of a CheckBox which is displayed next to the filename in a custom delegate. How can this be done? 回答1: I have used using the example Qt Quick Controls - File System Browser Example removing the part of the selection. The steps were the following: Add a new role in roleNames : QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE { QHash<int, QByteArray>

QFileSystemModel rowCount does not work as expected

不羁岁月 提交于 2019-12-12 12:15:59
问题 I am try an example in Model/View Programming. http://doc.qt.io/qt-5/model-view-programming.html To demonstrate how data can be retrieved from a model, using model indexes, we set up a QFileSystemModel without a view and display the names of files and directories in a widget. Although this does not show a normal way of using a model, it demonstrates the conventions used by models when dealing with model indexes. We construct a file system model in the following way: QFileSystemModel *model =

QTreeWidget and QFileSystemModel

[亡魂溺海] 提交于 2019-12-11 20:25:29
问题 Please tell me how to connect to QFileSystemModel QTreeWidget simply function SetModel() not support QFileSystemModel but only QAbstractItemModel, but I need to work with files and for these purposes QAbstractItemModel not fit, I would like to open files in directories climb QTreeWidget. Thanx 回答1: setModel is a private function in QTreeWidget. To use it, you could create a custom TreeWidget class that inherits QtreeWidget and QTreeView, create a public function setModel(QAbstractItemModel