Ah. Call the base class implementation. That makes sense.I'll try that and post the result later today. Thanks.
Ah. Call the base class implementation. That makes sense.I'll try that and post the result later today. Thanks.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Yep, that was it, of course. Thanks for your help!
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
How do I tell a row in the treewidget to redraw itself after it has been changed by a signal/slot connection?
I can't find anything. But I must be looking in the wrong place.
Thanks.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
In what way do you change the content of that row? It should update itself.
Of course you can force an update of a certain part of the widget/view, but I think there might be something wrong with your approach..
The forced update would look for example something like:
or
Qt Code:
setDirtyRegion(visualRect(item));To copy to clipboard, switch view to plain text mode
It updates itself when I call the base class setData function inside the derived setData function. If I don't, it won't. In some cases (some roles), I want to do something else with incoming data, and not call the base class function.
I assume that the base class function calls one of those update functions (which is how it happens 'automatically'). And maybe I have to do that too.
The update() function doesn't work.
Just to clarify, my setData function only changes one of those four private variables. So I'm not surprised the update doesn't happen automatically.
EDIT: I've found a solution. Not sure it's the best one. In the setData function, I call the QTreeWidgetItem::setText(int column, QString text). If there's a better way (I suspect there is a way which calls getData), please let me know.
Last edited by Michiel; 28th March 2006 at 19:33.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Yes, the base class implementation of setData() leads the internal tree model to emit dataChanged() signal which furthermore causes the view to update itself.
QTreeWidgetItem::setText(column, text) is exactly the same thanOriginally Posted by Michiel
QTreeWidgetItem::setData(column, Qt::DisplayRole, text)
Edit: I would suggest you to simply call the base class implementation, or what's the loss with that? You can pick your member variables and still call the base class implementation..
Qt Code:
// pick your variables if (role == Qt::EditRole) .. else if (role == Qt::UserRole) .. }To copy to clipboard, switch view to plain text mode
Last edited by wysota; 28th March 2006 at 20:21.
It might do a lot of redundant stuff. Like, set the text itself, then overwrite it again with my code.
Also, wouldn't it update before my data is changed?
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Umm..
Well, change the order. Do your stuff first and call the base class implementation afterwards..Originally Posted by Michiel
You could also do a trick like when your setData() receives a QDateTime variant with user role, you pick that date as a member variable and pass QDateTime.toString() with display role to the base class implementation.
But anyway.. don't take this as offense, but is there really any need for overriding data() and setData() at all? Unless you are gonna do some more customize stuff, you could avoid all this hassle and handle it by just simply overriding the operator used for comparing..
How could I intercept a user-edit of a field otherwise? If a user changes a date with the keyboard, I'll need QDateTime::fromString() to convert it to a date. As far as I can see, overwriting setData is the only way. And since I have to use it anyway, why not put everything else relevant in there too? I need a function to change _start and _end from the outside anyway. setData seems to do the trick.
That, and I'm just trying to program the way the qt developers probably intend me to. Since those functions are virtual, I think they should be overwritten by subclasses. I didn't know what other parts of QT relied on them.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
You could even place a QDateTimeEdit widget as an item widget in each item you intend to.Originally Posted by Michiel
The problem with overriding data() and/or setData() is that Qt's "convenience" itemviews rely on their strictly private model. So you really have to know what you're doing..Originally Posted by Michiel
You can set custom data with custom roles without overriding data() or setData(). Qt will just not handle them. Delegates are there for display and editing facilities for items.
I think I should have used QTreeView anyway. I'll probably change to that later. For now, I want a working program, and at the moment, it works.
Thanks again for your help.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Bookmarks