Results 1 to 3 of 3

Thread: Deleting rows from qdirmodel..

  1. #1
    Join Date
    Dec 2009
    Posts
    20
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default Deleting rows from qdirmodel..

    hi all,
    In the example below

    Qt Code:
    1. from PyQt4 import QtCore, QtGui
    2.  
    3. class Ui_Dialog(QtGui.QDialog):
    4.  
    5. def __init__(self,parent=None):
    6. QtGui.QDialog.__init__(self,parent)
    7. self.setObjectName("Dialog")
    8. self.resize(600, 500)
    9.  
    10.  
    11. self.model = QtGui.QDirModel()
    12. self.tree = QtGui.QTreeView()
    13. self.tree.setModel(self.model)
    14. print(self.model.flags(self.model.index("c:\Program Files")))
    15. self.model.setFilter(QtCore.QDir.Dirs|QtCore.QDir.NoDotAndDotDot)
    16.  
    17.  
    18. self.tree.setSortingEnabled(True)
    19.  
    20. self.tree.setRootIndex(self.model.index("c:\Program Files"))
    21.  
    22. #self.tree.hideColumn(1)
    23. #self.tree.hideColumn(2)
    24. #self.tree.hideColumn(3)
    25. self.tree.setWindowTitle("Dir View")
    26. self.tree.resize(400, 480)
    27. self.tree.setColumnWidth(0,200)
    28.  
    29. self.tree.show()
    30. QtCore.QObject.connect(self.tree, QtCore.SIGNAL("clicked(QModelIndex)"), self.test)
    31. QtCore.QMetaObject.connectSlotsByName(self)
    32.  
    33. self.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
    34.  
    35. def test(self,index):
    36.  
    37.  
    38. print(self.model.filePath(index))
    39.  
    40. print(self.model.rowCount(index))
    41.  
    42. #self.model.beginRemoveRows(index.parent(),index.row(),self.model.rowCount(index))
    43. #self.model.endRemoveRows()
    44.  
    45. print("Row of the index =",index.row())
    46.  
    47.  
    48. print("Parent = ",self.model.data(index.parent()))
    49.  
    50. if __name__ == "__main__":
    51. import sys
    52. app = QtGui.QApplication(sys.argv)
    53. ui = Ui_Dialog()
    54. #ui.show()
    55. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    i want to remove the row and it's children (if it has) when i click on it.. (The folder under click and it's children have to be removed) I know i'm making mistake patricularly in this line..
    Qt Code:
    1. self.model.beginRemoveRows(index.parent(),index.row(),self.model.rowCount(index))
    To copy to clipboard, switch view to plain text mode 
    Can u please help me in this regard .. Thanks..

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Deleting rows from qdirmodel..

    if you want remove items from a model, need call removeRows() function.

    QAbstractItemModel::beginRemoveRowsand QAbstractItemModel::endRemoveRows () are used to notify when a item has removed from the model, but not actually remove any items of the model.

    this functions are used when create a custom model and call removeRows() to remove item from the model.
    Last edited by ecanela; 10th February 2010 at 23:46. Reason: updated contents

  3. #3
    Join Date
    Dec 2009
    Posts
    20
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: Deleting rows from qdirmodel..

    Quote Originally Posted by ecanela View Post
    this functions are used when create a custom model and call removeRows() to remove item from the model.
    Thanks for your reply. But what should i do to remove rows from QDirModel...

Similar Threads

  1. Deleting rows (children) from a qstandarditem
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 29th March 2012, 16:04
  2. deleting QStringList
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 18th December 2009, 13:36
  3. Deleting a Folder
    By GTBuilder in forum Newbie
    Replies: 9
    Last Post: 29th September 2009, 06:22
  4. QMdiSubWindows - Deleting
    By Kerubu in forum Newbie
    Replies: 1
    Last Post: 25th August 2009, 05:23
  5. How to map the rows to sourceModel rows.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2009, 08:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.