qtreeview

Drag and drop within PyQt5 TreeView?

拥有回忆 提交于 2019-12-24 07:57:55
问题 I'm trying to implement a file directory using PyQt5. I'd like to incorporate drag and drop functionality within this tree to support both internal and external files (i.e. if I had some files on my desktop I'd like to be able to drop them into a folder in my PyQt view). This is what I have currently: from PyQt5.QtWidgets import QTreeView,QFileSystemModel,QApplication, QMenu, QAbstractItemView from PyQt5.QtCore import * from PyQt5.QtGui import * from src import config class Tree(QTreeView):

Drag and drop within PyQt5 TreeView?

旧城冷巷雨未停 提交于 2019-12-24 07:57:18
问题 I'm trying to implement a file directory using PyQt5. I'd like to incorporate drag and drop functionality within this tree to support both internal and external files (i.e. if I had some files on my desktop I'd like to be able to drop them into a folder in my PyQt view). This is what I have currently: from PyQt5.QtWidgets import QTreeView,QFileSystemModel,QApplication, QMenu, QAbstractItemView from PyQt5.QtCore import * from PyQt5.QtGui import * from src import config class Tree(QTreeView):

QTreeView always displaying the same data

送分小仙女□ 提交于 2019-12-24 07:38:30
问题 I have a tree of items. It is like this: Categorias (root) - General --- Computadoras --- Tablets - Insumos --- Cartuchos The problem is that the QTreeView is being completed always with the same information. I get a tree view looking like this: Categorias (root) - General --- General --- Insumos - Insumos --- General I have put a "print" in the index() method in order to see if the index was being created, and then, when I enter, for example, the "General" category for the first time,

QFileDialog for directories that have certain content

时光毁灭记忆、已成空白 提交于 2019-12-24 01:38:10
问题 I would like to build a dialog similar to QFileDialog::getExistingDirectory() for which the OK-button only is enabled when the selected directory contains certain files. I know I cannot achieve this with QFileDialog, instead I would have to come up with my own QDialog that has a QTreeView coupled to a QFileSystemModel. How can I limit the QTreeView to directories? How can I get the currently selected directory so I can check whether it contains some filenames? 回答1: Use setFilter on the

lazy loading child items Qtreeview

≡放荡痞女 提交于 2019-12-24 00:36:28
问题 I am trying to load child items in a treeview +top parent1 parent2 parent3 To start off I populate the model with parent node information only and attach it to a treeview, the tree looks like above. self.mytreeview=QtGui.Qtreeview() self.model=QtGui.QStandardItemModel(self.mytreeview) def initialise_model(self): '''Populate the model with parent nodes only''' #open file and process each line, each file line has the parent node info .... for file_name_entry in fileobject: parent_item=QtGui

How can I get the background color returned by model take precedence over the style

守給你的承諾、 提交于 2019-12-23 05:41:18
问题 I have a QTreeView rendering QAbstractItemModel , where I would like to set the background of certain cells based on the data in the model. I return QBrush from model::data(Qt::BackgroundColorRole) and it works until I apply a style to an item. Setting any style to the item (even something that has nothing to do with background color, e.g. styling the border) overrides the color I return from the model (the calls to the model querying the background color are made). I.e. the view behaves as

Qt4: Making “Simple Dom Model” editable; inserting rows

a 夏天 提交于 2019-12-23 04:14:13
问题 Basically, what I'm trying to achieve is combine "Editable Tree Model" and "Simple Dom Model" examples. So I'm having the latter as a base and I've copied the edit functions over there, changed the flags, setData , etc. I've already had success with editing entries. Now, I have a problem with adding rows to the model. Specifically, when I use insertAfter function in QDomNode::parentNode() , the model gets updated only internally. When I collapse and expand the parent, the added node(s) are

Highlight specific substrings in a QTreeView

左心房为你撑大大i 提交于 2019-12-23 01:06:34
问题 I want to highlight (or in general customise the formatting) of specific substrings appearing in a QTreeView in PyQt. To demonstrate what I mean, I have taken the example at PyQt4\examples\itemviews\dirview.pyw and manually added highlighting: Here all instances of the substring 'as' are highlighted, but in general it might not be a pattern match, I may actually want to be very specific. I know that this can be easily done to a QTextEdit as per this SO question, but that relied on moving

Qt what needs to be done for a custom model to enable drop?

怎甘沉沦 提交于 2019-12-22 10:37:09
问题 I'm trying to enable drop on a custom model I have hooked up to QTreeView . I've done the following: Ensured that acceptDrops is enabled on the QTreeView Implemented on my custom model supportedDropActions to return Qt::CopyAction | Qt::MoveAction Implemented on my custom model mimeType s to return a QStringList with text/uri-list Implemented on my custom model dropMimeData to handle the drop if it ever occurred. This is all I needed to get it working on a QTreeWidget . I've gone on to:

QTreeView & QAbstractItemModel & insertRow

十年热恋 提交于 2019-12-19 07:51:27
问题 I'm trying to implement QAbstractItemModel for QTreeView. I have problem with inserting rows. I noticed that if I insert at the beginning of my application all works fine. But If I insert rows later - after some other operations (like selections etc.) new items stay invisible. Moreover QTreeView seems to doesn't work at all! Do I have to emit some signals to notify QTreeView about rows insertion? This is my insertion method: bool LayersModel::insertRows(int position, int count, const