Here's my Filters.h
Here's my Filters.h
No it doesn't crash after I removed your code of "bla->viewport()->setMouseTracking" back to the correct form: "bla->setMouseTracking()".
Thats not the problem, it's slow, I could take a video, and what you will see is, me spinning and making my mouse go crazy on the treewidget list, and after several seconds it finally highlights one item, and when my mouse is not even on the list, it's still highlighted. Like as if, the treewidget picks randomly when it wants to highlight something. Then I spin my mouse all over the screen again and again, then finally some other random TreeItem highlights itself.
Why don't you try my solution?![]()
I'm sorry to say but it's not correct at all. It's the viewport widget which receives mouse move events.
That's most likely because you're not receiving those mouse move events but some other event causes an update every now and then, depending on if you enter and leave the widget or change the focus or something like that. Is the compilable example in post #15 that "slow"? Or did you even bother checking out out?Thats not the problem, it's slow, I could take a video, and what you will see is, me spinning and making my mouse go crazy on the treewidget list, and after several seconds it finally highlights one item, and when my mouse is not even on the list, it's still highlighted. Like as if, the treewidget picks randomly when it wants to highlight something. Then I spin my mouse all over the screen again and again, then finally some other random TreeItem highlights itself.
J-P Nurmi
1. Well doing bla->viewport()-> causes crash, that's 100% for sure, therefore it is not correct.
2. Maybe so, but of course why would I bother checking it out when I have the same code you showed me earlier in a different style?
@wysota: Your solution works great. Still trying to find out what went wrong with jpn's solution.
Last edited by VireX; 12th May 2007 at 16:08.
Again, the example works for fine. You must have a quirk of some kind in your code.
- Use a debugger
- examine the backtrace
- find a reason why does it crash
Because it would convince you that the approach works after all.2. Maybe so, but of course why would I bother checking it out when I have the same code you showed me earlier in a different style?
J-P Nurmi
Both your solutions work fine, in their isolated situations.
I just don't understand why it doesn't work with my MouseFilter class which is almost EXACTLY like jpn's program.
Why would Qt put setMouseTracking and installEventFilter in the QAbstracts if it was suppose to be used inside a class with viewport().
When I do TreeWidget->viewport()->setMouseTracking(true); it crashes, that's the SOLE reason. I think jpn doesn't realize i'm not talking about his program.
"Almost" sometimes makes a big difference. I have to agree with JP - you have to install the filter on the viewport and not the list itself. Event filters don't propagate - if the list installs a filter on its viewport and you install a fillter on the list, you won't get events for the viewport. You're having obvious errors in your code which JP already pointed out. You'll be receiving mouse move events only for that parts of the view which are not occupied by other widgets (viewport and scrollbars) and I doubt that's what you want.
Maybe so.
One question why doesnt using QPalette::Background or Window make the background become red? I tried different color roles in your code.
Also your code highlights each item in each column. Is there a way to highlight background of the whole row? (I have selection mode in selectRow).
No, you have to do it through editorEvent as I suggested earlier. But it's simpler to adjust the selection using an event filter. Here is a combined approach:
Qt Code:
// view is the parent if(view){ return true; } } } // view is the parent view->selectionModel()->clearSelection(); } }To copy to clipboard, switch view to plain text mode
I added that to delegate class but it made no difference.
Did you remember about enabling mouse tracking?
Here's my code, and mouse tracking does not change anything (I put mousetracking on list List->setMouseTracking(true); I even tried List->viewport()->setMouseTracking(true); nothing works):
Qt Code:
public: protected: void drawDisplay ( QPainter * painter, const QStyleOptionViewItem & option, const QRect &rect, const QString &text ) const{ QStyleOptionViewItem opt = option; //opt.font.setBold(true); } } // view is the parent if(view){ return true; } } } // view is the parent view->selectionModel()->clearSelection(); } } }; #include "Filters.moc"To copy to clipboard, switch view to plain text mode
"view is the parent" - is it true for you? Did you set the view as the parent of the delegate? Because if you didn't then it doesn't have a chance to workAnd remember to install the event filter on the viewport of the view, otherwise selection won't be cleared when you leave the view.
Why would I install the eventfilter, we dont use that for this. We dont use installEventFilter for this function. It would be easier if you showed me the exact code you used in like your main.cpp.
I did:
UserList->viewport()->setMouseTracking(true);
UserList->setItemDelegate(new Delegate(UserList->viewport()));
UserList->viewport()->setAttribute(Qt::WA_Hover, true);
Which is all you told me to do.
I think wysota meant more or less something like this:
Qt Code:
Delegate* delegate = new Delegate(UserList); // view as parent, not viewport UserList->viewport()->installEventFilter(delegate); // install event filter on the viewport UserList->setItemDelegate(delegate);To copy to clipboard, switch view to plain text mode
J-P Nurmi
Well all that did is take away the red bold hover on mouse over. Didn't fix the problem.
So why do you paste me the code that uses it?![]()
My main.cpp doesn't exist for a few days anymore, so this is not an option.It would be easier if you showed me the exact code you used in like your main.cpp.
No, I didn't. Hover attribute shouldn't be necessary and the viewport shouldn't be the parent of the delegate. Please verify that the if block in the editorEvent gets entered at all.I did:
UserList->viewport()->setMouseTracking(true);
UserList->setItemDelegate(new Delegate(UserList->viewport()));
UserList->viewport()->setAttribute(Qt::WA_Hover, true);
Which is all you told me to do.
Here, I implemented the thing again.
Last edited by wysota; 16th May 2007 at 09:06. Reason: Added the attachment
Nice it worked finally, I guess since I was using your old stuff and new stuff together it was conflicting and not showing up. And perhaps wrong parents etc.
Anyway I'm still wondering, how come selectionMode being SelectRow, yet the hover only highlights EACH column. Is it possible to code a way to highlight the WHOLE ROW, instead of a single column of the row?
Bookmarks