Results 1 to 19 of 19

Thread: QTreeView and StylingSheets for QTreeView

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Well...no joy! I tried QVariant, but still didn't change the header. When you have a free moment, would you mind trying to create a qFileSystemModel, and try to change the header please? Just wondering if setHeaderData() actually works on a Qfilesystemmodel, or if I'm doing something wrong somewhere. Wondering if the default headers are even editable.

    deriving from QFileSystemModel and reimplementing headerData()
    Can you explain this a bit more please? How do I reimplement headerData() ? Do you mean subClass QFileSystemModel? Or create a QstandardItemModel and copy the info from my QFileSystemModel? is that possible?

    Thanks!
    Cheers!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Quote Originally Posted by Nfrancisj View Post
    Just wondering if setHeaderData() actually works on a Qfilesystemmodel, or if I'm doing something wrong somewhere. Wondering if the default headers are even editable.
    Could very likely be the case that these are not modifyable.
    Hence the suggestion to overwrite headerData().

    Quote Originally Posted by Nfrancisj View Post
    Can you explain this a bit more please? How do I reimplement headerData() ? Do you mean subClass QFileSystemModel?
    Yes.
    Derive from (create a subclass of) the model class, then provide your own headerData() method.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTreeView and StylingSheets for QTreeView

    QFileSystemModel::headerData() is hard coded to return translated versions of "Name", "Size", "Type" or "Kind" and there is no implementation of setHeaderData(). You could use a simple subclass of QFileSystemModel. Something like:
    Qt Code:
    1. #!/usr/bin/python
    2. # -*- coding: utf-8 -*-
    3.  
    4. import sys
    5. from PyQt4 import QtGui, QtCore
    6.  
    7. class FileSystemModel(QtGui.QFileSystemModel):
    8. def __init__(self):
    9. QtGui.QFileSystemModel.__init__(self)
    10.  
    11. def headerData(self, section, orientation, role):
    12. if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
    13. if section == 0:
    14. result = self.tr('Foo')
    15. elif section == 1:
    16. result = self.tr('Bar')
    17. elif section == 2:
    18. result = self.tr('Baz')
    19. elif section == 3:
    20. result = self.tr('Bob')
    21. else:
    22. result = QtCore.QVariant()
    23. else:
    24. result = super(QtGui.QFileSystemModel, self).headerData(section, orientation, role)
    25. return result
    26.  
    27.  
    28. def main():
    29.  
    30. app = QtGui.QApplication(sys.argv)
    31.  
    32. m = FileSystemModel()
    33. m.setRootPath('/')
    34.  
    35. w = QtGui.QTreeView()
    36. w.setModel(m);
    37. w.resize(640, 480)
    38. w.move(300, 300)
    39. w.setWindowTitle('Simple')
    40. w.show()
    41.  
    42. sys.exit(app.exec_())
    43.  
    44.  
    45. if __name__ == '__main__':
    46. main()
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Instead of messing with the QFileSystemModel, I'd like to try and copy the data from it and transfer it to a QStandardItemModel.
    How do I do that? I saw on stackoverflow, there's a method "clone", but i cant seem to find it.

    I'm hoping there's a fancy Q Class/Method that will easily transfer data. .....but I'm guessing that I have to iterate through the model and add them based on the index, rows, and column.

    Cheers!
    Last edited by Nfrancisj; 14th July 2016 at 06:45.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Instead of making a small adjustment you want to create huge overhead in code and memory usage and manually synchronize between two models?

    Cheers,
    _

  6. #6
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Well, I'm not really writing anything for production. This is all just to learn how things work, and what's possible. I already know how to subclass, just trying to figure out Models.

    btw, for other newbies who are following, great explanation on models here:
    http://youtu.be/T0HXWcpPItk
    Last edited by Nfrancisj; 14th July 2016 at 16:37.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    ok, but in any real application you would go for either the subclass or a proxy model, never for duplicating data and keeping in manually synchronized.

    Cheers,
    _

  8. #8
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    Oh..Proxy Model is something new. Never heard of that.
    But thanks again for all your help guys.

  9. #9
    Join Date
    Oct 2019
    Posts
    7
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView and StylingSheets for QTreeView

    it's work look here : https://qss-stock.devsecstudio.com

Similar Threads

  1. Help ...QTreeView
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2009, 09:18
  2. QTreeView
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2009, 19:51
  3. QTreeView. Qt.4.4.1
    By janEUcitzen in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2008, 08:53
  4. QTreeView help
    By bepaald in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2007, 21:22
  5. QTreeView
    By merry in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2007, 08:38

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
  •  
Qt is a trademark of The Qt Company.