PDA

View Full Version : Setting text item in QTreeView



adrianoleal
22nd June 2011, 20:19
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.

Rachol
22nd June 2011, 20:40
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.

adrianoleal
22nd June 2011, 20:43
Hummm, i can try... But i will wait some time more, for to see if someone has another solution most simple.

Santosh Reddy
22nd June 2011, 20:58
...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.

kennylemon
4th July 2011, 09:32
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.
http://dl.dropbox.com/u/24137109/rename.png

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!!

kennylemon
5th July 2011, 12:50
Using QDir::rename() in custom model setData().

adrianoleal
11th July 2011, 18:56
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!

adrianoleal
12th July 2011, 14:48
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?