Results 1 to 8 of 8

Thread: Setting text item in QTreeView

  1. #1
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Setting text item in QTreeView

    Hello guys... How are you?

    Well, i'm newbie in Qt and have a big doubt. In my UI i have a QTreeView, ok! I show in this QTreeView the files of a folder in my computer, for this i set the filter of the QTreeView, also the model to QFileSystemModel... Ok, that's works!

    My problem right now, is... I need to change text of some items of the my QTreeView, aaaaand i saw that this not's possible in QTreeView, but is possible in QTreeWidget. Right, but in QTreeWidget, i can't to change model, in this class the method setModel() is private.

    How can i fix this? Someone can help me?

    In resume i need to change some text items of the my QTreeView. =/

    Thanks...

    PS: sorry my english.

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Setting text item in QTreeView

    It seems like a good solution to your problem would be to implement CustomModel inherited from QFileSystemModel. It is not the easiest for a beginner, but this is how I would do it.

  3. #3
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Setting text item in QTreeView

    Hummm, i can try... But i will wait some time more, for to see if someone has another solution most simple.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Setting text item in QTreeView

    ...I need to change text of some items of the my QTreeView...
    What do you mean by this?
    1. Do you want to change the file / folder names - Then use QFileSystemModel::setReadOnly(false), you can rename, copy and delete of files and directories.
    or
    2. Do you just what to display a specified file / folder with different name - Then you may use QAbstractProxyModel.

  5. #5
    Join Date
    Jun 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Setting text item in QTreeView

    Hi guys:

    I have the same problem.
    Although I subclass QFilesystemModel in two different ways, I still cannot rename a file.
    Both of these custom QFilesystemModel called setReaonly( false ) in its constructer.

    A. I implement some virtual functions, ex. data(), flags().
    But I did not implement setdata().
    Then, I try to rename a image file.
    However, I got this dialog.


    B. I implement some virtual functions, ex. data(), flags(), setdata().
    Try to rename a file, then I can get new file name in setdata().
    But, what should I do to rename the file correctly?!
    There are no related functions in QFileSystemModel to do rename functionality.

    Am I missing something?!
    Any advise, suggestion or simple example would be great.
    Thanks in advance!!

  6. #6
    Join Date
    Jun 2011
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Setting text item in QTreeView

    Using QDir::rename() in custom model setData().

  7. #7
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Setting text item in QTreeView

    What do you mean by this?
    1. Do you want to change the file / folder names - Then use QFileSystemModel::setReadOnly(false), you can rename, copy and delete of files and directories.
    or
    2. Do you just what to display a specified file / folder with different name - Then you may use QAbstractProxyModel.
    Second option. I will try use your suggestion and post the results. Thanks!
    Last edited by adrianoleal; 11th July 2011 at 18:07.

  8. #8
    Join Date
    Feb 2011
    Posts
    10
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Setting text item in QTreeView

    Quote Originally Posted by Santosh Reddy View Post
    What do you mean by this?
    1. Do you want to change the file / folder names - Then use QFileSystemModel::setReadOnly(false), you can rename, copy and delete of files and directories.
    or
    2. Do you just what to display a specified file / folder with different name - Then you may use QAbstractProxyModel.
    Well, i tried to understand what do with your second suggestion but i saw the documentation, i tried to implement but no sucess... If i to inherit the QAbstractProxyModel class in a new class called MyProxy, for example, i will can to use some methods in this new class that i used in QFileSystemModel? I'm really confused.

    Can you help me with a some code, please?

Similar Threads

  1. Setting SizeHint in QTreeView.
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2009, 11:03
  2. Setting an icon to an Item in a QlistWidget
    By LordQt in forum Qt Programming
    Replies: 18
    Last Post: 23rd August 2007, 22:24
  3. Setting one* column of QTreeView to be editable
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2006, 20:31
  4. setting row height in QTreeView?
    By gfunk in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2006, 00:47
  5. Can't change the text display of a QTreeview item.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2006, 01:03

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.